package com.bjpowernode.t01list;
import java.util.ArrayList;
/*
* 向集合中添加自定义类型 */public class TestList04 {public static void main(String[] args) {
ArrayList list = new ArrayList(); Student s1 = new Student("1001","jack",19); Student s2 = new Student("1002","paul",20); Student s3 = new Student("1000","james",16); Student s4 = new Student("1006","wade",17); Student s6 = new Student("1006","wade",17); Student s5 = new Student("1008","curry",12); list.add(s4); list.add(s1); list.add(s2); list.add(s3); //判断集合中是否包含传入的对象 //contains方法底层实际上就是调用了对象的equals方法 //所以建议在自定义类型的时候要重写equals方法 if(list.contains(s6)) { list.add(s5); } for(int i=0; i<list.size();i++) { System.out.println(list.get(i)); } }}