Set collection interface:
A Set is a Collection that cannot contain duplicate elements. The Java platform contains three general-purpose Set implementations: HashSet, TreeSet, and LinkedHashSet
HashSet: This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not
guarantee that the order will remain constant over time. This class permits the null element.
HashSet<String> hs =new HashSet<String>();
hs.add("Name 1");
hs.add("Name 2");
hs.add("Name 3");
A Set is a Collection that cannot contain duplicate elements. The Java platform contains three general-purpose Set implementations: HashSet, TreeSet, and LinkedHashSet
HashSet: This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not
guarantee that the order will remain constant over time. This class permits the null element.
HashSet<String> hs =new HashSet<String>();
hs.add("Name 1");
hs.add("Name 2");
hs.add("Name 3");
int sizehashset = hs.size();
System.out.println(sizehashset);
Iterator<String> itr=hs.iterator();
while(itr.hasNext()){
System.out.println(itr.next()); }
System.out.println(sizehashset);
Iterator<String> itr=hs.iterator();
while(itr.hasNext()){
System.out.println(itr.next()); }
hs.contains(Object) ;
hs.clear();
TreeSet : TreeSet provides an implementation of the Set interface that uses a tree for storage. Objects are stored in sorted, ascending order. The TreeSet class implements NavigableSet interface that extends the SortedSet interface. Access and retrieval times are quite fast.
LinkedHashSet : LinkedHashSet is between HashSet and TreeSet. It is implemented as a hash table with a linked list running through it, so it provides the order of insertion.
LinkedHashSet maintains a linked list of the entries in the set, in the order in which they were inserted. This allows insertion-order iteration over the set.
This comment has been removed by the author.
ReplyDeleteInspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeleterpa training in Chennai | best rpa training in chennai
rpa training in pune
rpa online training | rpa training in bangalore
I would really like to read some personal experiences like the way, you've explained through the above article. I'm glad for your achievements and would probably like to see much more in the near future. Thanks for share.
ReplyDeleteData Science training in Chennai | Data science training in bangalore
Data science training in pune| Data science online training
Python training in Kalyan nagar
Pleasant Tips..Thanks for Sharing….We keep up hands on approach at work and in the workplace, keeping our business pragmatic, which recommends we can help you with your tree clearing and pruning in an invaluable and fit way.
ReplyDeletejava training in omr | oracle training in chennai
java training in annanagar | java training in chennai
After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
ReplyDeletePython training in marathahalli
Python training institute in pune