Iterate around an ArrayList using Iterator

Example below shows how to iterate around an ArrayList.

Example

public class IteratingArrayList {
	public static void main(String[] args) {
		List<Integer> arrayList = new ArrayList<Integer>();

		arrayList.add(100);
		arrayList.add(101);
		arrayList.add(102);

		Iterator<Integer> arraylistIterator = arrayList.iterator();

		while (arraylistIterator.hasNext()) {
			Integer number = arraylistIterator.next();
			System.out.println(number);
		}
	}
}

Output

100
101
102

Leave a Reply

Your email address will not be published. Required fields are marked *