import java.util.ArrayList;
public class 泛型 {
public static void main(String[] args){
ArrayList<String> collection1 = new ArrayList<>();
collection1.add("new york");
collection1.add("newew york");
collection1.add("newdafs york");
ArrayList<String> collection2 = new ArrayList<>();
collection2.add("nedscsw yorkdsac");
collection2.add("newedsacw yordcask");
collection2.add("newdacsfs yodcsacrk");
collection1.addAll(collection2);//将collection2元素加到collection1中
collection1.clear();//清除collection1中元素
int n = collection1.size();//获取collection1大小
collection1.remove("newdafs york");//清除具体元素
collection1.contains("newdafs york");//是否包含
collection1.add("a");//添加元素
collection1.retainAll(collection2);//交集
System.out.println(collection1);
}
}
public class 泛型 {
public static void main(String[] args){
ArrayList<String> collection1 = new ArrayList<>();
collection1.add("new york");
collection1.add("newew york");
collection1.add("newdafs york");
ArrayList<String> collection2 = new ArrayList<>();
collection2.add("nedscsw yorkdsac");
collection2.add("newedsacw yordcask");
collection2.add("newdacsfs yodcsacrk");
collection1.addAll(collection2);//将collection2元素加到collection1中
collection1.clear();//清除collection1中元素
int n = collection1.size();//获取collection1大小
collection1.remove("newdafs york");//清除具体元素
collection1.contains("newdafs york");//是否包含
collection1.add("a");//添加元素
collection1.retainAll(collection2);//交集
System.out.println(collection1);
}
}