I have one arraylist
in the store class :
ArrayList<Empleado> listaEmpleados = new ArrayList<>();
That arraylist
includes employees and in that class I visualize them perfectly.
I need to send the arraylist
with all employees to another class.
I have tried creating a method:
public ArrayList<Empleado> getDatos() {
return listaEmpleados;
}
And in class two:
Almacen alm = new Almacen();
ArrayList<Empleado> nuevoalmacen = alm.getDatos();
but it comes out empty.
Hello Paco and welcome to StackOverflow in Spanish.
Let's start with your code:
What you should do is the following:
When you call tu
Clase2
from tuClase1
you will be doing something like this:In this way, what you do is call the class, so when you declare the variable
alm
you do it by initializing it, but you don't pass any value to it.I recommend doing it this way:
And that
Clase2
you have this for example: