如何在父自定义对象数组列表中获取自定义对象子列表中的单个项目位置?

How to get custom object sub list individual item position in parent custom object array list?

我有一个名为 StudentData 的 Class。 StudentData class 具有 id(唯一)、名称、地址等参数。现在我有两个 StudentData class 的 ArrayList,其中一个包含 10 个项目的 ArrayList,另一个包含 50 个项目的 ArrayList。 现在我的问题是,有没有更好的方法来找出 50 项列表中 10 项的单独位置?

我是这样尝试的,如有错误请指正

ArrayList<Integer> allId = new ArrayList<>();
outerLoop:
 for (int i = 0; i < totalList.getSmallList().size(); i++) {
    for (int position = 0; position < totalList.getBigList().size(); position++) {
         if (totalList.getSmallList().get(i).getID() == totalList.getBigList().get(position).getID()) {
         allId.add(totalList.getBigList().get(position).getID());
         continue outerLoop;
       }
     }
   }

如果我没有误会你的话。您想获取小列表中匹配项的(bigList 的)索引,并将它们添加到单独的 allIdd;

ArrayList<Integer> allId = new ArrayList<>();
outerLoop:
 for (int i = 0; i < totalList.getSmallList().size(); i++) {
    for (int position = 0; position < totalList.getBigList().size(); position++) {
         if (totalList.getSmallList().get(i).getID() == totalList.getBigList().get(position).getID()) {
         allId.add(posotion);
         continue outerLoop;
       }
     }
   }

编辑:

根据您的评论: 将 bigList 添加到 listAdapter 上面会给你突出显示的内容