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");
At this point there are three elements in the Stooges. Note: The list cannot be added at this time, otherwise it will report "Java.lang.UnsupportedOperationException", Arrays.aslist () returns a list, and is a fixed-length list, So it cannot be converted to ArrayList and can only be converted to Abstractlist
The reason is that the Aslist () method returns the list form of an array, and the returned list is just another view of the array, and the array itself does not disappear, and any action on the list is ultimately reflected on the array. So the Remove,add method is not supported.
- String[] arr = {"1", "2"};
- List List = Arrays.aslist (arr);
- 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));
- 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);
- 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");
- SYSTEM.OUT.PRINTLN (list);
- String[] arr = (string[]) List.toarray (new String[list.size ()]);
- System.out.println (arrays.tostring (arr));
Java list map set array conversion