package test1;
import java.util.ArrayList;
public class testArrayList {
public static void main(String args[]) {
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<10;i++) {
list.add((int)(Math.random()*100));
}
System.out.println(list);
ArrayList<Integer> twolist=new ArrayList<>();
twolist=getArrayList(list);
System.out.println("偶数有:"+twolist);
Student student[]=new Student[3];
for(int i=0;i<3;i++)
{
student[i]=new Student();
}
student[0].setName("qwer");
student[0].setNumber(20180000);
student[0].setSex("男");
student[1].setName("asdf");
student[1].setNumber(20180001);
student[1].setSex("男");
student[2].setName("zxcv");
student[2].setNumber(20180002);
student[2].setSex("女");
ArrayList<Student> studentList=new ArrayList<>();
studentList.add(student[0]);
studentList.add(student[1]);
studentList.add(student[2]);
list.size();
Student stu=new Student();
for(int i=0;i<studentList.size();i++)
{
stu=studentList.get(i);
System.out.println("名字:"+stu.getName()+" 学号"+stu.getNumber()+" 性别:"+stu.getSex());
}
Arrayprint(studentList);
}
public static ArrayList<Integer> getArrayList(ArrayList<Integer> bigList){
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<bigList.size();i++) {
if(bigList.get(i)%2==0)
list.add(bigList.get(i));
}
return list;
}
public static void Arrayprint(ArrayList<Student> bigList)
{
Student stu=new Student();
for(int i=0;i<bigList.size();i++){
stu =bigList.get(i);
System.out.println("名字:"+stu.getName()+" 学号"+stu.getNumber()+" 性别:"+stu.getSex());
}
}
}
package test1;
public class Student {
private String name;
private int number;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}