Add "a", "a", "C", "C", "a" five elements to the set collection and the list collection respectively, observing that the duplicate value "a" can be successfully added in the list collection as well as in the set collection.
PackageCom.hanqi.jihe;ImportJava.util.*; Public classTest3 { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsSYSTEM.OUT.PRINTLN ("list"); List<String> ls=NewArraylist<>(); Ls.add (A); Ls.add (A); Ls.add (C); Ls.add (C); Ls.add (A); Iterator<String> it=Ls.iterator (); while(It.hasnext ()) {System.out.print (" "+It.next ()); } System.out.println ("\ n"); System.out.println ("Set"); Set<String> st=NewHashset<>(); St.add (A); St.add (A); St.add (C); St.add (C); St.add (A); Iterator<String> ite=St.iterator (); while(Ite.hasnext ()) {System.out.print (" "+Ite.next ()); } }}
The duplicate value "a" can be successfully added in the list collection as well as in the set collection.
Java Collection Exercises 2