Tag:java list collection
import java.util.list;import java.util.arraylist;class listdemo{ @SuppressWarnings (value= "unchecked") public static void main (String[] args) { list list = new arraylist (); list.add (; ) list.add (New integer); list.add (" One ") list.add (New string (" one "); list.add (New student ("One", ' M ',)); list.add (New student ("A", "F",)); student student = new student (); student.setname ("threE "); student.setsex (' F '); student.setage (+); list.add (student); list list_repeat = new arraylist (); list_repeat.add (; ) list_repeat.add (student); boolean bool_list = list.containsall (list_repeat);//contains List_repeat collection boolean bool_obj = list.contains (student);//contains Student objects list.remove (0);//move out of the set No. 0 element list.remove (student);//move out the elements of the student object in the collection list.removeall ( list);//Empty set &NBSP;&NBSP;&NBSp; system.out.println (Bool_list) ; system.out.println (Bool_obj); system.out.println (List.size ()); System.out.println ("----------"); student s = null; for ( Int i=0;i<list.size (); i++) { if ( List.get (i) instanceof student) { s = (Student) list.get (i); system.out.println ("Name:" + s.getname () + ", Sex:" + s.getsex () + ", Age:" + s.getage ()); }else{ system.out.println (List.get (i)); } } }}class student{ private String name; private char sex; private int age; public student () { } public student (string name,char sex,int age) { super (); this.name = name; this.sex = sex; this.age = age; } public void setname (String name) { this.name = name; } public string getname () { return this.name; } public void setsex (char sex) { this.sex = sex; } public char getsex () { return this.sex; } public void setage (int age) { this.age = age; } public int getage () { return this.age; }}
This article is from the "Forest Sensitive" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1774387
Big Data Java Foundation day job