I have a Matchmaker class which initializes an ArrayList to store objects of my user class.
//Class which keeps user objects in its ArrayList called Database
MatchMaker myData = new MatchMaker();
//My user object
user tempUser;
ArrayList<String> emails = new ArrayList<String>();
emails = JSONRead.read();
//Create a user at every loop, initialized by a email (String):
for (int i = 0; i < emails.size(); i++) {
tempUser = new user(emails.get(i));
myData.Database.add(tempUser);
System.out.println("User at position " + i + ": " + myData.Database.get(i).get("Firstname"));
}
The result in this loop is:
User at position 0: Luat
User at position 1: Pim
Outside that loop I try print every object which should be in my ArrayList:
//Print out every user in my ArrayList
for(int i = 0 ; i < myData.Database.size() ; i ++){
System.out.println("User at position " + i + ": " +m yData.Database.get(i).get("Firstname"));
}
The result in this loop is:
User at position 0: Pim
User at position 1: Pim
What is the problem here, it seems the last object which was added is duplicated throughout my ArrayList? State if I must post more information about my user class.