web-api
answered Sep 15 '21 00:00
1. use for loop to iterate through ArrayList and get the value of each element
for(int i=0; i<ids.size(); i++) {
String id=ids.get(i);
}
2. Use Iterator interface to iterate through ArrayList and get the value of each element
Iterator<String> i=ids.iterator();
while(i.hasNext()){
String s =i.next();
}
in above code ,hasNext() method returns true if the iteration has more elements. so it keep looping until Iterator have element.
next() method returns the next element in the iteration. at the start, it will return the first element and so on.