In hashset, i am able to print the objects added using sysout of obj name and also by iterating and returning the elements. what is the difference? both gives the objects stored in the hash set.
Below is the code :
public static void main(String[] args) {
HashSet<Integer> hs= new HashSet<Integer>();
hs.add(12);
hs.add(234);
Iterator<Integer> it = hs.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
System.out.println(hs);
}