数组,List,Set相互转化

数组转set,数组,List,Set相互转化 转载:https://blog.csdn.net/my_precious/article/details/53010232

数组,List,Set相互转化

数组转set,数组,List,Set相互转化

转载:https://blog.csdn.net/my_precious/article/details/53010232

1.数组转化为List:

String[] strArray= new String[]{"a", "b", "c"};

List strList= Arrays.asList(strArray);

2.数组转Set

String[] strArray= new String[]{"a", "b", "c"};

Set<String> staffsSet = new HashSet<>(Arrays.asList(staffs));

staffsSet.add("d"); // ok

staffsSet.remove("a"); // ok

3.List转Set

String[] staffs = new String[]{"a", "b", "c"};

List staffsList = Arrays.asList(staffs);

Set result = new HashSet(staffsList);

4.set转List

String[] staffs = new String[]{"a", "b", "c"};

Set<String> staffsSet = new HashSet<>(Arrays.asList(staffs));

List<String> result = new ArrayList<>(staffsSet);

数组,List,Set相互转化的相关内容如下:

数组怎么转set| set可以存储重复元素吗| list转set| string数组转为set| set包含哪个元素| set转数组| byte数组转string| js数组转字符串|

标题:数组,List,Set相互转化|http://www.wc10086.cn/413442.html

本文来自网络,不代表本站立场,转载请注明出处!