Created
September 10, 2021 02:18
-
-
Save h-hub/8ba30fe12ac84d52f113fe6e5e260fc9 to your computer and use it in GitHub Desktop.
Iterator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
public class ItrExample { | |
public static void main(String[] args) { | |
List<String> list2 = List.of("item11","item22","item33"); //create a list | |
Iterator<String> itr = list2.iterator(); // create list iterator | |
while(itr.hasNext()){ | |
System.out.println(itr.next()); | |
} | |
Map<String,String> map = new HashMap<String,String>(); //create a map | |
map.put("item1", "item1-content"); | |
map.put("item2", "item2-content"); | |
map.put("item3", "item3-content"); | |
Iterator entrySIterator = map.values().iterator(); //create map values iterator | |
while(entrySIterator.hasNext()){ | |
System.out.println(entrySIterator.next()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment