| Learn | Java - Lists - Iterating over elements in a list |
|---|
| Iterating over elements in a list For the example, lets say that we have a List of type String that contains four elements: "hello, ", "how ", "are ", "you?" The best way to iterate over each element is by using a for-each loop: Which would print: To print them all in the same line, you can use a StringBuilder: Will print: Alternatively, you can use element indexing ( as described in Accessing element at ith Index from ArrayList (opens new window) ) to iterate a list. Warning: this approach is inefficient for linked lists. |
Read Article
https://develop.horje.com/learn/1434/reference