运用知识点
import java.util.ArrayList;
import java.util.Random;
public class Test03 {
public static void main(String[] args) {
ArrayList<Integer> cList = cList();
ArrayList<Integer> oList = oList(cList);
for(Integer a : cList ) {
System.out.print(a+" ");
}
System.out.println();
for(Integer a : oList ) {
System.out.print(a+" ");
}
}
public static ArrayList cList() {
ArrayList<Integer> list = new ArrayList<>();
Random random = new Random();
for (int i = 1; i <= 20; i++) {
list.add(random.nextInt(100));
}
return list;
}
public static ArrayList oList(ArrayList<Integer> list) {
ArrayList<Integer> oList = new ArrayList<>();
for(int num : list) {
if (num%2==0) {
oList.add(num);
}
}
return oList;
}
}