1 PackageCom.wtd;2 3 Importjava.util.ArrayList;4 ImportJava.util.HashSet;5 ImportJava.util.Iterator;6 Importjava.util.List;7 ImportJava.util.Set;8 9 Public classL16 {Ten One /** A * @desc need to pass the list to another method how to use the list to traverse userlist and dplist? - * @paramargs - * @throwsException the */ - Public Static voidMain (string[] args)throwsException { - //TODO auto-generated Method Stub -List List =NewArraylist<arraylist>(); +User user=NewUser (); -User.setage (18); +User.setname ("Andi"); ADepartment department=NewDepartment (); atDepartment.setdepartid (7); -Department.setdepartname ("program"); -List<user> userlist =NewArrayList ();//used to receive data isolated from the database - userlist.add (user); -List<department> dplist =NewArrayList ();//used to receive data isolated from the database - Dplist.add (department); in List.add (userlist); - List.add (dplist); to getelement (list); + } - Public Static voidGetElement (List List)throwsexception{ the for(Iterator Iterator =list.iterator (); Iterator.hasnext ();) { *ArrayList Listsmall =(ArrayList) Iterator.next (); $ for(Iterator Iterator2 =listsmall.iterator (); Iterator2.hasnext ();) {Panax NotoginsengObject objectsmall=Iterator2.next (); -String ClassName =Objectsmall.getclass (). GetName (); the if("Com.wtd.User". Equalsignorecase (ClassName)) {//Com.wtd.User +System.out.println ("classname.user=" +className); AUser usersmall=(User) Objectsmall; theSystem.out.println ("User.Name:" +usersmall.getname () + "\r\nuser.age:" +usersmall.getage ()); +}Else if("Com.wtd.Department". Equalsignorecase (ClassName)) { -System.out.println ("classname.department=" +classname);//com.wtd.Department $Department departmentsmall=(Department) Objectsmall; $System.out.println ("Department.departname:" +departmentsmall.getdepartname () + "\r\ndepartment.departid:" +Departmentsmall.getdepartid ()); - } - the } - Wuyi } the - } Wu - } About $ classuser{ - intAge ; - String name; - Public intGetage () { A returnAge ; + } the Public voidSetage (intAge ) { - This. Age =Age ; $ } the PublicString GetName () { the returnname; the } the Public voidsetName (String name) { - This. Name =name; in } the the } About the classdepartment{ the intDepartid; the String Departname; + Public intGetdepartid () { - returnDepartid; the }Bayi Public voidSetdepartid (intDepartid) { the This. Departid =Departid; the } - PublicString Getdepartname () { - returnDepartname; the } the Public voidsetdepartname (String departname) { the This. Departname =Departname; the } - the}
Resolve the issue raised by this URL: http://q.cnblogs.com/q/79494/
The collection list stores the list, traversing the object elements of the bottommost list.