I'm having trouble retreiving data from a list. The values never seem to get stored, or the object is initialized? I made a class that stores some variables:
public class storage{
public int a = 0;
public int b = 0;
}
then I created another class which fills a, and b with some values and stores the object in a list
public class anotherclass{
public List<storage> alldata = new ArrayList<storage>();
public void filldata(){
storage tmp = new storage();
for (int i = 1; i <= 10; i++){
tmp.a = i;
tmp.b = i;
alldata.add(tmp);
}
}
}
but when I run filldata() in my main class, then try to get the object from the list a and b are still set at 0.
public static void main(String[] args){
anotherclass obj = new anotherclass();
obj.filldata()
for (int i = 0; i <= obj.alldata.size() - 1; i++){
System.out.println(obj.alldata.get(i).a)
System.out.println(obj.alldata.get(i).b)
//Outputs as all zeroes
}
}
How could this be?