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;
}
}
iterator()method would only exist if you defined it in your class. Since you are defining your own LinkedList class (I assume as coursework since there's already a robust LinkedList class in the standard library), you have to write your own implementation of the Iterator class and return an instance of it in a method of your LinkedList class.