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

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

    This is how I solved it. I forgot that sublist was a direct reference to the elements in the original list, so it makes sense why it wouldn't work.

    ArrayList inputA = new ArrayList(input.subList(0, input.size()/2));
    

提交回复
热议问题