Method that creates a new list based on elements of an existing list?

1

In C # there is the function numeros.GetRange(0, quant);

I would like to know which function is equivalent to numeros.GetRange(0, quant); of C # in Java

    
asked by anonymous 12.03.2016 / 20:42

1 answer

3

To pick up a piece from one list and put it in another, you can use subList() .

You should pass as the parameter the initial index (it will be included in the new list) and the end (it will not be included in the new list);

Eg:

ArrayList<Integer> novaLista = numeros.subList(0, indexFinal);
    
12.03.2016 / 20:51