1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/* Iterate through elements Java ArrayList using Iterator Example This Java Example shows how to iterate through the elements of java ArrayList object using Iterator. */ import java.util.ArrayList; import java.util.Iterator; public class IterateThroughArrayListUsingIteratorExample { public static void main(String[] args) { //create an ArrayList object ArrayList arrayList = new ArrayList(); //Add elements to Arraylist arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); //get an Iterator object for ArrayList using iterator() method. Iterator itr = arrayList.iterator(); //use hasNext() and next() methods of Iterator to iterate through the elements System.out.println("Iterating through ArrayList elements..."); while(itr.hasNext()) System.out.println(itr.next()); } } /* Output would be Iterating through ArrayList elements... 1 2 3 4 5 */ |
This program doesn’t work
Amit here
Nice tuts
gooood…………..
this program is not working correct it
You need to have the mentioned readChar.txt file in the proper location. Otherwise it throws FileNotFoundException.
In addition, It returns Unicode char, so it might display as ? in the console.
Gud
ths code is wrng not work
nice one ….
good
ty..
Still helpful 9 years on… thanks 🙂