java - Troubles with ArrayList -
i having trouble storing objects in arraylist
.
i want populate arraylist
simple object called variable
. has 2 string attributes: name , value. problem when add new variable
object list, attributes of added variable
objects appear null. also, instead of being added end of list, new object inserted @ first position.
here code :
arraylist<variable> variables = new arraylist<variable>(); variable author = new variable(); author.setname("author"); author.setvalue("lusyo"); variables.add(author); system.out.println(variables.get(0).getname()); variable scenario = new variable(); author.setname("scenario"); author.setvalue("login"); variables.add(scenario); system.out.println(variables.get(0).getname()); system.out.println(variables.get(1).getname());
the output :
author scenario null
as can see, scenario
located @ index 0, should not be. can't figure out what's going on code.
thank in advance !
variable scenario = new variable(); author.setname("scenario"); author.setvalue("login");
does disturb there? :)
Comments
Post a Comment