How to convert an array, list, Set, and map to each other in Java.

Source: Internet
Author: User

1. Array goto list:

string[] countries = {"Array", "List", "Set", "Map"};

List List = arrays.aslist (countries);

2.Array turn : Set

String [] countries = {"Array", "List", "Set"};

set<string> set = new Hashset<string> (arrays.aslist (countries));

SYSTEM.OUT.PRINTLN (set);

3. List to array:

list<string> list = new arraylist<string> ();

List.add ("Array");

List.add ("List");

List.add ("Set");

List.add ("Map");

String [] countries = List.toarray (New String[list.size ()));

4. Map to List:

list<value> list = new arraylist<value> (Map.values ());

5. Map Turn set:

Map<integer, string> map = Createmap ();

set<string> set = new Hashset<> (Sourcemap.values ());

6. List Turn set:

String[] staffs = new String[]{"Array", "List", "Set"};

List staffsList = Arrays.asList(staffs);

Set result = new HashSet(staffsList);

How to convert an array, list, Set, and map to each other in Java.

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.