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