1 Public Static voidMain (string[] args) {2 3list<string> array =NewArraylist<string> ();//Create an array4 5Set<string> HashSet =NewHashset<string> ();//Create HashSet6 7 //Array.add ("A", "a", "C", "C", "a"); Not applicable8 9Array.add ("A");TenArray.add ("a"); OneArray.add ("C");//adding characters AArray.add ("C"); -Array.add ("a"); -System.out.print ("After adding elements after the collection List:"); the - for(String T:array) -{//Traverse Output -System.out.print (t + ""); + - } +Hashset.add ("A");//adding characters AHashset.add ("a"); atHashset.add ("C"); -Hashset.add ("C"); -Hashset.add ("a"); -System.out.println (""); - -System.out.print ("Add after element collection set:"); in for(String S:hashset)//Traverse Output - { toSystem.out.print (S + "")); + } -
Operation Result:
Add post-element collection list:a a C c a
Add post-element collection set:c a c a
Conclusion: Duplicate values can be saved in the list collection, and the set collection cannot hold duplicate values.
1.22 P235 The second problem is to add "a", "a", "C", "C", "a" five elements to the set and list set, and observe if the duplicate value "a" can be successfully added in the Set and list collection.