List,set,map, inter-array conversion

Source: Internet
Author: User

List,set,map, inter-array conversion
1.list Turn Set
Set set = New HashSet (new ArrayList ());

2.set Goto List
List List = new ArrayList (new HashSet ());

3. Array to List
List stooges = arrays.aslist ("Larry", "Moe", "Curly");
Or
String[] arr = {"1", "2"};
List List = Arrays.aslist (arr);

4. Array to set
Int[] A = {1, 2, 3};
Set set = New HashSet (Arrays.aslist (a));

5.map of the relevant operation.
Map map = new HashMap ();
Map.put ("1", "a");
Map.put (' 2 ', ' B ');
Map.put (' 3 ', ' C ');
SYSTEM.OUT.PRINTLN (map);
All values are output
System.out.println (Map.keyset ());
All keys are output
System.out.println (Map.values ());
Convert the value of map to list
List List = new ArrayList (Map.values ());
SYSTEM.OUT.PRINTLN (list);
Convert the value of map to set
Set set = New HashSet (Map.values ());
SYSTEM.OUT.PRINTLN (set);

6.list Turn Array
List List = Arrays.aslist ("A", "B");
String[] arr = (string[]) List.toarray (new String[list.size ()]);
System.out.println (arrays.tostring (arr));

List,set,map, inter-array conversion

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.