之前看到有很多Collection转化成List集合的案例,但是试了集合里面都不能带实体,自己试着发现了一种方法可以用于带实体的Collection与List集合转换~
//交集--a和b是自己创建的实体List集合
Collection<T> intersection= CollectionUtils.intersection(a,b);
System.out.println(T);
//Collection转化成List
Iterator<T> entity = intersection.iterator();
List<T> entityList =new ArrayList<>();
while (entity .hasNext()){
T needEntity= entity.next();
entityList .add(needEntity);
}
System.out.println(entityList );