The best way to convert a list, Array, Map, set, and other sets in Java

Source: Internet
Author: User

In Java, we often need to do some conversion to list, array, etc., of course there are many kinds of conversion methods, but which method is both convenient and efficient? Let me introduce you to the best conversion method between sets.convert 1.List to array
list<string> list = new arraylist<string> (), List.add ("China"), List.add ("Switzerland"); List.add ("Italy") ); List.add ("France"); String [] countries = List.toarray (New String[list.size ()));
2.Array Conversion to List
string[] countries = {"China", "Switzerland", "Italy", "France"}; List List = arrays.aslist (countries);
3.Map Conversion to List
list<value> list = new arraylist<value> (Map.values ());
4.Array conversion to set
String [] countries = {"India", "Switzerland", "Italy"};      set<string> set = new Hashset<string> (arrays.aslist (countries)); SYSTEM.OUT.PRINTLN (set);
5.MAP conversion to set
Map<integer, string> sourcemap = Createmap (); set<string> targetset = new hashset<> (Sourcemap.values ());


The best way to convert a list, Array, Map, set, and other sets 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.