I have problem with this code,when I add map object to list,all previous added object will be changed.how can I declare map as non static?
for(Statment){
map.put(Key,value),
}
result.add(map);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you add something to a container, you are adding the reference (not a copy of the object it references) If you want to add a copy (so that if you can change the original, and the copy added to the list does not change) you have to explicitly copy it.
e.g.