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.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.