Java中List与Set相互转化

  在进行数据类型转换时,可能会遇到List与Set的相互转化,可行的方式有如下示例:

// List转Set
List<String> tmpList = new ArrayList<>();
Set<String> tmpSet = new HashSet<>(tmpList);


// Set转List
Set<String> tmpSet = new HashSet<>();
List<String> tmpList = new ArrayList<>(tmpSet);

 

posted @ 2020-05-26 22:44  晒太阳的兔子很忙  阅读(9051)  评论(0编辑  收藏  举报