【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
【逗号拼接的字符串------->数组】
String str = "a,b,c,1,2,3";
String[] strArray = str.split(",");
【数组------->逗号拼接的字符串】
String str = org.apache.commons.lang.StringUtils.join(strArray , ",");
需要引入Apache Commons组件中的个commons-lang.jar包
【Array------->List】
String[] strArray = {"a","b","c","1","2","3"};
List<String> strList = java.util.Arrays.asList(strArray);
【List-------> Array】
String strArray = strList.toArray(new String[0]); //new String[0]是指定返回数组的类型);
【List------->Set】
Set<String> strSet = new HashSet<>(strList);
【Set------->List】
List<String> strList = new ArrayList<>(strSet);
【Array------->Set】
Set<String> strSet = new HashSet<>(Arrays.asList(strArray));
【Set------->Array】
String[] strArray = strSet.toArray(new String[0]); //new String[0]是指定返回数组的类型);
【map的keys】
Map<String,String> map = new HashMap<>();
map.put("a","a");
map.put("b","b");
map.put("c","c");
map.put("1","1");
map.put("2","2");
map.put("3","3");
Set set = map.keySet();
【map的values】
List<String> list = new ArrayList<String>(map.values());
Set<String> set = new HashSet<String>(map.values());
来源:oschina
链接:https://my.oschina.net/u/2320053/blog/3022834