14.7-2

Source: Internet
Author: User

1  PackageJihe;2 3 ImportJava.util.*;4 5  Public classTest {6     7      Public Static voidMain (string[] args)8     {9         //create an instance of the Set classTenSet<string> set =NewTreeset<>(); One          A         //adding elements -Set.add ("A"); -Set.add ("a"); theSet.add ("C"); -Set.add ("C"); -Set.add ("a"); -          +         //iterating through the collection -          for(String x:set) +         { ASystem.out.println ("set =" +x); at         } -          -          -          -          -          in         //to create an instance of the list class -list<string> list =NewArraylist<>(); to          +         //adding elements -List.add ("A"); theList.add ("a"); *List.add ("C"); $List.add ("C");Panax NotoginsengList.add ("a"); -          the         //iterating through the collection +          for(String x:list) A         { theSYSTEM.OUT.PRINTLN ("list =" +x); +         } -          $          $     } -  -}

Run results

Set = A
Set = C
set = a
Set = C
List = A
List = a
List = C
List = C
List = a

14.7-2

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.