Different way to iterate over collection in Java

Collection Frameworks helps to store data in data structure. In order to get our data from collection we require some techniques to get the data. Iteration is one way. All other way to iterate are:-

  1. forEach method : It was introduced in Java 8
  2. Enhanced for each loop : It was introduced in Java 5
  3. Iterator : It was introduced in Java 2. Using java.util.Iterator, we can manipulate the collection elements with the help of additional methods such as hasNext, next, etc.
  4. Loop Method : Traditional loop method is still used to iterate over indexed collection as Lists.


Comments

Popular posts from this blog

Healthy Diet and Lifestyle

System Design