Java list分批处理数据之subList()
作者:互联网
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for (int i = 1; i <= 1000; i++) { list.add(i); } System.out.println(list.size()); //注意:subList(),会修改原有list,如果后续代码需要用list的数据,需要慎重!!! while (true) { System.out.println(list.size()); if (list != null && list.size() > 300) { List<Integer> newList = list.subList(0, 300); System.out.println(newList.size()); //很重要!!! newList.clear(); } else { System.out.println(list.size()); break; } } }
标签:Java,300,newList,list,System,subList,size 来源: https://www.cnblogs.com/fujingtao5470/p/15127243.html