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

猜你喜欢

转载自www.cnblogs.com/bien94/p/12969270.html