Thursday, 15 October 2015

HashSet example in java

import java.util.*;
public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet<String> hs = new HashSet<String>();
hs.add("India");
hs.add("Amrica");
hs.add("Singapore");
hs.add("Nepal");
System.out.println("The value of HashSet is " +hs);
Iterator<String> it = hs.iterator();
while(it.hasNext()){
String s = it.next();
System.out.println("the value is " +s);
}
}

}

output:-
The value of HashSet is [Amrica, Singapore, Nepal, India]
the value is Amrica
the value is Singapore
the value is Nepal
the value is India

No comments:

Post a Comment