Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. public boolean add(String s) {
  2.         int loc = gethashIndex(s); // get the LinedList index
  3.  
  4.         if(table[loc] == null) {// if the LinkedList has not been instanced yet.
  5.             table[loc] = new LinkedList<>(); // Create a instance
  6.             return table[loc].add(s); //and simply add the String to the list and return true if no errors occurred
  7.         } else {
  8.             //We have to loop through the LinkedList to make sure there are no duplicates.
  9.             for (String s2 : table[loc]) {
  10.                 if(s2.equals(s))
  11.                     return false;
  12.             }
  13.             //if there is no duplicate, add the String to this LinkedList (we are probably over capacity now)
  14.             return table[loc].add(s); //add the String to the list and return true if no errors occurred
  15.         }
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement