Monday, January 7, 2013

Java - Various ways to iterate a Set

A Set is a collection that contains no duplicate elements. Below are the methods in which you can iterate a Set

1. For each loop (introduced from Java 5)
2. Array and While loop (here you can use for loop as well)
3. Using Iterator

Please see the below code.