List集合转成Set集合(如果List集合的元素有重复,转成Set集合就会去掉重复的数据,每条数据只保留一条)

//List转化成Set
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
Set<String> set = new HashSet<String>();
set.addAll(tableList);

Set集合转化成List集合

//Set转化成List
//方法一
Set<String> set = new HashSet<String>();
set.add("a");
set.add("b");
set.add("c");
List<String> list = new ArrayList<String>(set);
//方法二
Set<String> set = new HashSet<String>();
set.add("a");
set.add("b");
set.add("c");
List<String> list = new ArrayList<String>();
Iterator it=set.iterator();
while(it.hasNext())
{
    list.add(it.next());
}    

 

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-10-11
  • 2021-08-08
  • 2021-07-10
  • 2021-06-28
  • 2021-11-21
  • 2021-04-15
猜你喜欢
  • 2022-12-23
  • 2021-06-21
  • 2021-10-20
  • 2021-06-11
  • 2021-12-15
  • 2021-08-14
  • 2021-09-25
相关资源
相似解决方案