电光石火-穿越时空电光石火-穿越时空


数组,List,Set互转

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);

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => 数组,List,Set互转
本文地址:http://www.ilkhome.cn/index.php/archives/594/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 数组,List,Set互转,谢谢。

评论