Dave's Brain

Browse - Programming Tips - How do I enumerate a HashSet?

Date: 2014mar25
Language: Java
Keywords: iterate

Q.  How do I enumerate a HashSet?

A.  Its totally easy.

HashSet<String> set = new HashSet<String>(); set.add("one"); set.add("two"); set.add("three"); for (String s : set) { // Very simple code to enumerate // The elements will not be the order they were added System.out.println(s); }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.