Both methods have a pointer to the move, and the difference is that one returns a Boolean and a return object:
Hasnext (): Determines whether the current element exists and does not point to the move
Next (): Returns the current element and refers to the next element
Take a look at the code:
linkedhashmap<string, string> myMap = new linkedhashmap<string, string> ();
MyMap. Put ("0", "0.0");
MyMap. Put ("1", "1.0");
MyMap. Put ("2", "2.0");
Set<string> MySet = Mymap.keyset ();
int i=0,j=0;
for (iterator<string> Iterator = Myset.iterator (); Iterator.hasnext ();) {// last i=3
Iterator.hasnext ();//The execution of this method here does not affect the overall traversal
i++;
String Theone=iterator.next ();
System.out.println (i+ "--" +theone);
}
for (iterator<string> Iterator = Myset.iterator (); Iterator.hasnext ();) {// last j=2
j + +;
String Theone=iterator.next ();
System.out.println (j+ "--" +theone);
Iterator.next ();//The execution of this method here affects the execution of the overall traversal
}
The Hasnext method and next method of Iterator