Error in method - using Iterator to interweave a List

前端 未结 2 434
甜味超标
甜味超标 2021-01-15 01:03

I\'ve created a method that should interweave two list objects and return the new, inter-weaved, list.

i.e. If aList is [A,C,E,G] & bList is [B, D, F] the metho

2条回答
  •  萌比男神i
    2021-01-15 01:29

    I believe this can be done in a more simple way, using while(iterator.hasNext()) idiom:

    itrA = a.iterator();
    itrB = b.iterator(); 
    
    while (itrA.hasNext() || itrB.hasNext()) {
      if (itrA.hasNext())
          newList.add(itrA.next());
      if (itrB.hasNext())
          newList.add(itrB.next());
    }
    

提交回复
热议问题