无题
发表于 |更新于
list中删除的最好方式
5. 通过Stream的过滤方法,因为Stream每次处理后都会生成一个新的Stream,不存在并发问题,所以Stream的filter也可以修改list集合。(**建议,简单高效**)
123456public List<String> streamRemove() { List<String> students = this.getStudents(); return students.stream() .filter(this::notNeedDel) .collect(Collectors.toList());}
通过removeIf方法,实现元素的过滤删除。从Java 8开始,List接口提供了removeIf方法用于删除所有满足特定条件的数组元素(推荐)
1arraylist.removeIf(this::needDel);
BitSet常见的使用例子往往和大数相关:
==现在有1千万个随机数,随机数的范围在1到1亿之间。求出将1到1亿之间没有在随机数中的数 ...