How can I slice an ArrayList out of an ArrayList in Java?

前端 未结 5 1979
故里飘歌
故里飘歌 2020-12-02 16:10

How do I get an array slice of an ArrayList in Java? Specifically I want to do something like this:

ArrayList inputA = input.sub         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 16:53

    I have found a way if you know startIndex and endIndex of the elements one need to remove from ArrayList

    Let al be the original ArrayList and startIndex,endIndex be start and end index to be removed from the array respectively:

    al.subList(startIndex, endIndex + 1).clear();
    

提交回复
热议问题