Unless otherwise mentioned, all Java examples are tested on Java 6, Java 7 and Java 8 versions. // An iterator for lists that allows the programmer to traverse the list in either direction, modify the list during iteration. The hasNext () method returns true if the iteration has more elements. Largest free Technical and Blogging resource site for Beginner. Your email address will not be published. 1. void java.util.stream.Stream.forEach(Consumer 1. Seven (7) ways to Iterate Through Loop in Java. "\n==============> 3. We can use the enhanced for loop to iterate over elements of the LinkedHashSet objects as given below. Note that for some collection, such as List, we still can use the index to traverse normally. Thymeleaf is a popular server-side template engine for Java-based web and standalone applications. Object.values 3. Iterator enables you to cycle through a collection, obtaining or removing elements. If we simply want to display contents of the list, we can do that by converting list to a string using toString()function and then simply printing it as shown below: Download Run Code list = [1, 3, 5, 7, 9] for i in list: print(i) chevron_right. Iterable.forEach() Example....", // collection Stream.forEach() util: Returns a sequential Stream with this collection as its source, "\n==============> 7. It takes the object that you want to iterate over as an argument and returns an array containing all properties names (or keys). Map interface didn’t extend a Collection interface … jstl supports a forEach loop to iterate over collections and here is how: