//List declaration
List<String> fruits =new ArrayList<>();
fruits.add("Apple");
fruits.add("watermelon");
fruits.add("Pear");
fruits.add("banana");
//Iterator<Stromg>Declaration of
Iterator<String> it2= fruits.iterator();
//Use hasNext to continue the loop if there is a value
while(it2.hasNext()){
//Use next to get the value
String nation = it2.next();
System.out.println(nation);
}
Recommended Posts