Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean add(String s) {
- int loc = gethashIndex(s); // get the LinedList index
- if(table[loc] == null) {// if the LinkedList has not been instanced yet.
- table[loc] = new LinkedList<>(); // Create a instance
- return table[loc].add(s); //and simply add the String to the list and return true if no errors occurred
- } else {
- //We have to loop through the LinkedList to make sure there are no duplicates.
- for (String s2 : table[loc]) {
- if(s2.equals(s))
- return false;
- }
- //if there is no duplicate, add the String to this LinkedList (we are probably over capacity now)
- return table[loc].add(s); //add the String to the list and return true if no errors occurred
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement