Java:迭代数组列表 [英] Java: Iterating through an Array List

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

问题描述

我有一个ArrayList,其中包含我想要执行方法'count'的实例化对象的名称。不过,我不确定是否/如何做到这一点。我有一个循环来扫描数组列表,并添加了伪代码我想要实现的目标。

I have an ArrayList containing names of instantiated objects that I want to execute the method 'count' on. I'm unsure if/how to do that, though. I have a loop to scan through the array list, and added pseudocode with what I'm trying to achieve.

    n = 0;
    while(n <= arrayList.size()){
        (arrayList.get(n)).count();
    }

我是java的新手,我不确定这是可能的,但任何帮助将不胜感激。谢谢。

I'm new to java and am not sure this is possible, but any help would be appreciated. Thanks.

推荐答案

更简单的方法...

ArrayList<MyObject> list = ...
for( MyObject obj : list)
  obj.count()

这篇关于Java:迭代数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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