java - Arraylist Index adding with hashmap? -


inside arraylist need add hashmap values , declared arralist

public static arraylist<map<string, object>> uploadingarray = new arraylist<>();  , map  map<string,object> image_details=new hashmap<>(); ,    int imageid;  for(int i=0;i<4;i++){    imageid=i;    new method()   } 

image id change when function calling activity imageid=(another activity).imageid;

  new method(){     image_details.put("imageid",i);     image_details.put("status","new");     uploadingarray.add(imageid,image_details);  }   result of uploadingarray  [0] id=3; status=new [1] id=3; status=new [2] id=3; status=new [3] id=3; status=new 

why id same position? 1 know issue please me? model "i" value changed calling method

they have same values because you're adding same object multiple times arraylist.

you should create new map object inside loop:

arraylist<map<string, object>> list = new arraylist<>();  for(int = 0; < 4; i++){     // creating new object on every iteration     map<string, object> imagedetails = new hashmap<>();      imagedetails.put("imageid", i);     imagedetails.put("status", "new");      list.add(imageid, imagedetails); } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -