How to use arraylist if I have 2 java class. Login and profile. If 2 user logs in, after submit button it will go to another java class and then will display their name, age, address. Thank you so much
2 Answers
What you might want to consider is the service locator pattern. You could provide a simple service that is composed of the List and then given as a dependency to other classes.
class ArrayListService {
private final List<MyObject> list;
public ArrayListService(ArrayList<MyObject> list) {
this.list = list;
}
public List<MyObject> getList() {
return list;
}
}
Comments
One thing that might work is making the ArrayList public and static. This way you will be able to access it from anywhere in the application (i.e. any class).
1 Comment
Jason
Viable solution but definitely not conventional or best practice.
ArrayList<Object>or use a common interface