package test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; public class CreateArrayList { public static void main(String[] args) { List<Integer> newList = create(10); System.out.println(Arrays.toString(newList.toArray())); List<Integer> deleteList = delete(newList,5); System.out.println(Arrays.toString(deleteList.toArray())); } public static List<Integer> create(int size){ Random r = new Random(); List<Integer> list = new ArrayList<>(); for(int i=0;i<size;i++) { int temp = r.nextInt(size); list.add(temp); } return list; } public static List<Integer> delete(List<Integer> needList,int flagIndex){ for(int i=0;i<needList.size();) { if(needList.get(i).intValue()<flagIndex) { needList.remove(i); i=0; }else { i++; } } return needList; } }
程序创建一个ArrayList,添加1到10的10个随机数,删除大于5的数 java
原文:https://www.cnblogs.com/QAZLIU/p/9332730.html