fill arraylist with arraylist attribute information of another class

Asked

Viewed 40 times

-1

I have an Event class with an attribute arraylist<string>lista. I fill this attribute in a Telalista Jframe and use a evento.setLista("informaçao"); to add the textField string to the arraylist of the Event class. I would like to know how I can use this information that was saved by the set in another class. I tried to do the following:

        ArrayList<String> st = new ArrayList();   
        Evento ev = new Evento();
        st = ev.getLista();
        
      for (int i = 0; i < st.size(); i++) {         
            System.out.println("teste" + st.get(i) );
        } 
    }

but this st array is empty...

The Jframe I commented that is filling with the setLista is like this:

Evento listaTipo = new Evento();
listaTipo.setLista(textFieldNome.getText());  

anyone has any idea how I can get the arraylist st of the other class in question to be filled with the information I saved in jframe?

1 answer

0

John, clearly the list will come empty because you have two different instances. Your instances are:

Evento ev = new Evento();

And the other instance you filled out the list is this:

Evento listaTipo = new Evento();

To recover the values of the Type list, you should use the same instance. That is, you should do something like:

Evento listaTipo = new Evento();
listaTipo.setLista(textFieldNome.getText()); 

ArrayList<String> st = new ArrayList();   
st = listaTipo.getLista();

Browser other questions tagged

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