There are 5 ways to iterate over a List:
1. For Loop
for (int i = 0; i < pList.size(); i++) {
System.out.println(pList.get(i));
}
2. For-each Loop
for (String temp : pList) {
System.out.println(temp);
}
3. iterate via "iterator loop"
Iterator<String> pList = pList.iterator();
while (pList.hasNext()) {
System.out.println(pList.next());
}
4.while loop
int i = 0;
while (i < pList.size()) {
System.out.println(pList.get(i));
i++;
}
5. collection stream() util: A sequential stream is returned with this collection as its source.
pList.forEach((temp) -> {
System.out.println(temp); }