Using ArrayList [closed]

0

I wanted to know if there is any way to remove the elements of an ArrayList from a certain index to the first element. That is, given an ArrayList of characters, I want to delete all the elements from the index 4 for example up to the index 0. Is there any practical way to do this?

    
asked by Jorge DeSpringfield 11.10.2018 в 11:04
source

2 answers

0

You can use a while loop to eliminate them, so it would look like this:

int indice = 4;

ArrayList<String> ropa = new ArrayList<String>();
ropa.add('Camiseta');
ropa.add('Pantalón');
ropa.add('Zapatilla');
ropa.add('Jersey');

while(indice > 0){
    ropa.remove(indice);
    indice--;
}
    
answered by 11.10.2018 / 11:09
source
0

Given a List Fulllist that you want to delete from the start to the x position, including:

private List<MiObjeto> eliminarElementos(List<MiObjeto> listaCompleta, int posicion){
    return listaCompleta.sublist(posicion, listaCompleta.size());
}

It basically consists in making a new list without those elements, not in erase.

    
answered by 11.10.2018 в 11:44