One Point about For Each Loop I Ridiculously Forgot

Laughing at me! ;)
Laughing at me! ;)
It is very shameful that I forgot this simple point and had written a post on for-each loop previously.The point is that for-each loop can be used to iterate through an iterator. See this snippet..
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){
It is not just for an ArrayList but for any iterator.
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

Posted by at on

Tags: Java Introduction,