我有一个 Matchmaker 类,它初始化一个ArrayList来存储用户类的对象。
var dataset = [10,20,30,2,32,4,1];
elements = d3.select("body").selectAll("p")
.data(dataset)
elements
.enter()
.append("p");
elements.text(function(d){return(d);});
此循环的结果是:
//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"));
}
在该循环之外,我尝试打印应该在我的ArrayList中的每个对象:
User at position 0: Luat
User at position 1: Pim
此循环的结果是:
//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"));
}
这里有什么问题,似乎添加的最后一个对象在我的ArrayList中是重复的?如果我必须发布有关用户类的更多信息,请说明。