1、Map和List
map.values转list:
Collection<Object> values = resultMap.values();
ArrayList<Object> resultList = new ArrayList(values);
2、Map和Set
map转set(主要用于迭代遍历),注意是无序的
map.keySet();
map.entrySet();
set转map就是遍历添加暂无提供简便方法
3、List和Set(一般是用来去重)
list转set
List<String> list = new ArrayList<>();
HashSet<String> toSet = new HashSet<String>(list);
set转List
list.addAll(toSet);
4、List和String[]
list转String[]
List<String> list = new ArrayList<>();
String[] string = new String[list.size()];
list.toArray(string);
String[]转list
String[] string = new String[]{"data"};
List<String> list = Arrays.asList(string);
5、Set和String[]
set转string[]
Set<String> set = new HashSet<String>();
set.add("data");
String[] string = set.toArray(new String[set.size()]);
string[]转set(其实是set和list的转换)
String[] string = new String[]{"data"};
Set<String> set = new HashSet<String>(Arrays.asList(string));