简体   繁体   中英

in java,how to iterate list of objects

i am having the list myEmpls

List myEmpls = new ArrayList();

In this list i have added used defined objects.

LogConf e = getLogs(el);
    //add it to list
 myEmpls.add(e);

Now how to iterate the list of objects and get the values from this objects. How to do this?

You could just google this and you would find tons of solutions.. But here is the code:

for(LogConf element : myEmpls) {
  System.out.println(element.getValue());
}

You should also get used to define the type of the elements in the list:

List<LogConf> myEmpls = new ArrayList<LogConf>();

I know its been some time since this post was made. You can also use the Iterator.

              List myEmpls = new ArrayList();
              Iterator itr = myEmpls.iterator();

              while(itr.hasNext()) {   
                   LogConf Logobj = (LogConf) itr.next();
                   System.out.println(Logobj.getterName());
              }

Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM