List转Set[通俗易懂]

List转Set[通俗易懂]List 转 Set List myList new ArrayList myList add 1 myList add 1 Set result new HashSet myList Set 转 List String str new String Tom Bob Jane Set set new HashSet

List转Set

List myList = new ArrayList();
myList.add("1");
myList.add("1");
Set result = new HashSet(myList);

Set转List

String[] str = new String[]{"Tom", "Bob", "Jane"};
Set set = new HashSet<>(Arrays.asList(str));

List result = new ArrayList<>(set);

数组转List

String[] str = new String[]{"Tom", "Bob", "Jane"};
List list = Arrays.asList(str);

数组转Set

String[] str = new String[]{"Tom", "Bob", "Jane"};
Set set = new HashSet<>(Arrays.asList(str));

List转数组

String[] str = new String[]{"Tom", "Bob", "Jane"};
List list = Arrays.asList(str);

Object[] result = list.toArray();

Set转数组

String[] str = new String[]{"Tom", "Bob", "Jane"};
Set set = new HashSet<>(Arrays.asList(str));

Object[] result = set.toArray();
编程小号
上一篇 2025-03-22 19:27
下一篇 2025-04-09 23:17

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/132111.html