在java中,如何迭代对象列表 [英] in java,how to iterate list of objects

查看:172
本文介绍了在java中,如何迭代对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有清单 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>();

这篇关于在java中,如何迭代对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆