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

前端 未结 5 1961
故里飘歌
故里飘歌 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:48

    If there is no existing method then I guess you can iterate from 0 to input.size()/2, taking each consecutive element and appending it to a new ArrayList.

    EDIT: Actually, I think you can take that List and use it to instantiate a new ArrayList using one of the ArrayList constructors.

提交回复
热议问题