Delete all items from a list and add them to another list


I have a method that removes nodes from a list until it is empty. What I need is that after I empty it, I add the elements that I removed to a new list. Here is the method:

public void vaciarD(){
    while(!estaVacia()){ //mientras que la lista no esté vacía seguirá eliminando nodos
        eliminarInicio(); //metodo para quitar nodos de la lista           

I tried to do this but my program was cycled and no longer answered:

public void vaciarD(){
        agregarAlFinal2(eliminarInicio()); //mandar como parametro el nodo eliminado

In JavaFX, the person in charge of executing the method is:

public void vaciarD(ActionEvent e){
        JOptionPane.showMessageDialog(null, "No hay registros de peliculas.");

Method of addingAlFinal2:

public void agregarAlFinal2(Peliculas dato){
if(! estaVacia()){
    fin = new NodoDoble(dato, null, fin);
    fin.anterior.siguiente = fin;

    inicio = fin = new NodoDoble(dato);
tamanio2 ++;

Delete methodHome:

public Peliculas eliminarInicio(){
    Peliculas elemento = inicio.dato;
    if(inicio == fin){
        inicio = fin = null;
        inicio = inicio.siguiente;
        inicio.anterior = null;
    return elemento;
asked by Antonio 12.11.2018 в 07:11

0 answers