The collection list stores the list, traversing the object elements of the bottommost list.

Source: Internet
Author: User

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.

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.