Mega Code Archive

 
Categories / Java / Collections Data Structure
 

Listing the Elements of a Collection(iterate over the elements of set or list)

import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main {   public static void main(String[] argv) throws Exception {     Set collection = new HashSet();     // For a set or list     for (Iterator it = collection.iterator(); it.hasNext();) {       Object element = it.next();     }   } }