How can I iterate over a Set/HashSet without the following?
Set
HashSet
Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }
You can use an enhanced for loop:
Set<String> set = new HashSet<String>(); //populate set for (String s : set) { System.out.println(s); }
Or with Java 8:
set.forEach(System.out::println);
1.4m articles
1.4m replys
5 comments
57.0k users