using two iterators in one ArrayList

后端 未结 5 1331
遇见更好的自我
遇见更好的自我 2021-01-19 09:16

Edit: Thank you for all your prompt replies. Now I see the assignment won\'t work. From another thread I read that iterator in Java is much less powerful than iterator in C+

5条回答
  •  猫巷女王i
    2021-01-19 09:31

    Do this:

    ArrayList aList = new ArrayList();
    // do something to fill the list
    for (int i = 0; i < aList.size(); i++)
    {
      ArrayList bList = aList.subList(i, aList.size());
      for (int j = 0; j < bList.size(); j++)
      {
        // do stuff with the sublist
      }
    }
    

    It's important to note that bList is backed by aList so changes to bList will be reflected in aList...make non-structural changes only to keep your sanity.

提交回复
热议问题