Big Data Day 10th

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.