查找数组上的集合索引

时间:2012-12-03 07:40:11

标签: java

我有以下循环

    for (Annotation currAnnotation : annotation.getAnnotations())
    {
        List<Map<String, String>> list = annotation.getList();
list.get(index)

索引应该是循环的索引,我该如何实现呢? 我需要从列表中获取具体条目。

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以使用计数器:

int index = 0;
for (Annotation currAnnotation : annotation.getAnnotations())
{
    List<Map<String, String>> list = annotation.getList();
    ... list.get(index) ...
    index++;
}