InterviewSolution
| 1. |
What Is For-each Style Loop? |
|
Answer» Another feature which was added to COLLECTION with JDK 5 is for-each style loop. Any collection which wants to be the TARGET of the "for-each loop" STATEMENT has to implement iterable interface. Using for-each loop is easier than constructing the iterator to ITERATE over the collection and can be used in most of the cases RATHER than using the iterator loop. If you have a list of Strings, that can be iterated using for-each loop like this. for(String city : cityList){ Another feature which was added to Collection with JDK 5 is for-each style loop. Any collection which wants to be the target of the "for-each loop" statement has to implement iterable interface. Using for-each loop is easier than constructing the iterator to iterate over the collection and can be used in most of the cases rather than using the iterator loop. If you have a list of Strings, that can be iterated using for-each loop like this. for(String city : cityList){ |
|