1.List转换为Array
List<String> list = new ArrayList<>();
list.add("AAAA");
list.add("BBBB");
list.add("CCCC");
list.add("DDDD");
String [] array = list.toArray(new String[list.size()]);
2.
Array转换为List
String[] countries = {"AAAA", "BBBB", "CCCC", "DDDD"};
List list = Arrays.asList(countries);
3.
Map的Key值转换为List
Map<Integer,String> map = new HashMap<>();
map.put(1,"AAAA");
map.put(2,"BBBB");
map.put(3,"CCCC");
map.put(4,"DDDD");
List<Integer> list = new ArrayList<Integer>(map.keySet());
4.
Map的Value值转换为List
Map<Integer,String> map = new HashMap<>();
map.put(1,"AAAA");
map.put(2,"BBBB");
map.put(3,"CCCC");
map.put(4,"DDDD");
List<String> list = new ArrayList<String>(map.values());
5.
Array转换为Set
String [] countries = {"AAAA", "BBBB", "CCCC", "DDDD"};
Set<String> set = new HashSet<String>(Arrays.asList(countries));
注:如果Array中存在相同的值,Set中只会存在一个
6.
Map的Key值转换为Set
Map<Integer,String> map = new HashMap<>();
map.put(1,"AAAA");
map.put(2,"BBBB");
map.put(3,"CCCC");
map.put(4,"DDDD");
Set<Integer> set = new HashSet<>(map.keySet());
7.
Map的Value值转换为Set
Map<Integer,String> map = new HashMap<>();
map.put(1,"AAAA");
map.put(2,"BBBB");
map.put(3,"CCCC");
map.put(4,"DDDD");
Set<String> set = new HashSet<String>(map.values());