数组,List,Set相互转化
- 工作小总结
- 时间:2021-01-14 11:32
- 3396人已阅读
简介
1.数组转化为List:String[] strArray= new String[]{"Tom", "Bob", "Jane"};List strList= Arrays.asList(strArray);2.数组转SetString[]strArray=newStr
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
1. 数组转化为List:
String[] strArray= new String[]{"Tom", "Bob", "Jane"}; List strList= Arrays.asList(strArray);
2. 数组转Set
String[] strArray= new String[]{"Tom", "Bob", "Jane"};
Set<String> staffsSet = new HashSet<>(Arrays.asList(staffs));
staffsSet.add("Mary"); // ok
staffsSet.remove("Tom"); // ok
3. List转Set
String[] staffs = new String[]{"Tom", "Bob", "Jane"}; List staffsList = Arrays.asList(staffs); Set result = new HashSet(staffsList);
4. set转List
String[] staffs = new String[]{"Tom", "Bob", "Jane"}; Set<String> staffsSet = new HashSet<>(Arrays.asList(staffs)); List<String> result = new ArrayList<>(staffsSet);
上一篇: 【jd】