/ *
* Using the stored string and traversing HashSet
*
* the Set features:
* disorder (sequential storage and reading may not be the same)
* must be unique
* not an integer index
On the contrary List
*/
public class HashSetDemo { public static void main (String [] args) { // create the collection object HashSet <String> HS = new new HashSet <String> (); // add elements hs.add ( " Hello " ); hs.add ( " World " ); hs.add ( " Java " ); // hs.add ( "Java"); // traversing a collection of objects for (String S: HS) { System.out.println (S); } } }
Export