Set里面是如何运用removeAll()方法的
Set里面是如何运用removeAll()方法?
Set里面是如何运用removeAll()方法?
2018-03-14
public class SetTest { public Set<Course> Set_CourseToSelect; public Course c; public Course e; public Course[] cc; public Course[] ee; public SetTest() { Set_CourseToSelect=new HashSet<Course>(); } public void Add() { //1.add(): c=new Course(1,"java"); e=c; Set_CourseToSelect.add(c); //2.addAll(): cc=new Course[]{new Course(2,"C"),new Course(3,"C#")}; ee=cc; Set_CourseToSelect.addAll(Arrays.asList(cc)); } public void Remove() { //3.remove(): //Set_CourseToSelect.remove(e); //4.removeAll(): Set_CourseToSelect.removeAll(Arrays.asList(ee)); } public void Get() { System.out.println("-----------------------"); for(Course c:Set_CourseToSelect) { System.out.println(c.id+":"+c.name); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub SetTest st=new SetTest(); st.Add(); st.Remove(); st.Get(); } }
举报