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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -