Method to create a new list based on elements from an existing list?

Asked

Viewed 38 times

1

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

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

  • What is numeros? One List?

  • @jbueno yes is ArrayLis numeros = new ArrayLis();

  • You could improve your question. Instead of searching for a "translation" of GetRange, request a function to create a new list based on elements from an existing list. (Just to score, the negative wasn’t mine, I think that’s a good question, it just wasn’t well crafted).

  • 1

    @jbueno now you talking I understood this function, because I did not know

  • Perfect, good to help you!

1 answer

3


To take a piece of a list and put it in another, you can use the subList().

You must pass as parameter the initial index (will be included in the new list) and the final (will not be included in the new list);

Ex.:

ArrayList<Integer> novaLista = numeros.subList(0, indexFinal);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.