How can i fix linkedlist using with iterator in Java?

43 Views Asked by At

When create a linkedlist in hash class search method, my iterator does not work with it. What can i use instead of iterator? How can i fix it.

public static void search(String keyword){
    String hashString = hash(new String(keyword.toLowerCase()));
    if (maps.containsKey(hashString)) {
        LinkedList<String> list = maps.get(hashString);

        Iterator iter = list.iterator();
        System.out.println("This word has been appeared in following text files: ");
        while (iter.hasNext()) {
            System.out.print(iter.next() + "");
            if (iter.hasNext()) {
                System.out.print(", ");
            }
        }
        System.out.println("");
    } else {
        System.out.println("No text files includes this word.");
    }
    System.out.println("");
}

package hash;

public class LinkedList<Item> {
Node<Item> first;
Node<Item> last;
int size = 0;

public LinkedList(){
    first = null;
    last = null;
    size = 0;
}
}
0

There are 0 best solutions below