1, remove (int index); //Delete the element at the specified position
2, remove (Object o); //Delete the specified object and examine the rules for deleting objects?
3, RemoveAll (Collection col);//delete all elements in the specified collection.
4, contains (Object O); //Whether it contains
5, contains (Collection col);//Whether the collection is included.
Package It18zhang;
Import java.util.ArrayList;
Import java.util.List;
/*
* 1, remove (int index);//delete the element at the specified position
2. Remove (object o);//delete the specified object, what is the rule that examines the object being deleted?
3, RemoveAll (Collection col);//delete all elements in the specified collection.
4, contains (Object o);//Whether it contains
5, contains (Collection col);//Whether the collection is included.
*/
public class Removedemo {
public static void Main (string[] args) {
TODO auto-generated Method Stub
List<student> list=new arraylist<student> ();
Student s1=new Student ("S1", 10);
Student s2=new Student ("S2", 11);
Student s3=new Student ("S3", 11);
Student s4=new Student ("S4", 12);
System.out.println ("Add objects via Add");
List.add (S1);
List.add (S2);
List.add (S3);
List.add (S4);
GetList (list);
System.out.println ("Delete object with remove");
List.remove (S1);
List.remove (S2);
GetList (list);
System.out.println ("Delete all objects by RemoveAll");
List.removeall (list);
GetList (list);
System.out.println ("by obtain to determine whether to include");
System.out.println ("contains S1" +list.contains (S1));
System.out.println ("contains S4" +list.contains (S4));
System.out.println ("If the Obtainall contains a list");
System.out.println ("contains" +list.containsall (list));
}
private static void GetList (List<student> List) {
TODO auto-generated Method Stub
for (int i=0;i<list.size (); i++) {
Student S=list.get (i);
System.out.println ("This is the first" +i+ "Student" +s.getname () +s.getage ());
}
}
}
Class student{
private int age;
private String name;
Public Student (String name, int.) {
TODO auto-generated Constructor stub
This.name=name;
This.age=age;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
}
Big Data Day 10th