Laughing at me! ;) |
It is not just for an ArrayList but for any iterator.
ArrayList<String> as=new ArrayList<String>();
as.add("Item 1");
as.add("Item 2");
as.add("Item 3");
as.add("Item 4");
for(String st:as){
System.out.println(st);
}
In fact, for each loop is designed for this. But I forgot that. I apologize for the readers that I had missed that most-important point in that post. I thought of updating it, but I need to show off my mistake, so did I write this post. Also take a look at what oracle has written about for-each loop.
Photo credit: Wikimedia
No comments:
Post a Comment