1

I am saving in an arraylist in this way ("name", "surname", "id", "email", "score")

I trying to edit a user in this arraylist by first searching using id and that part i'm ok with it but then I need to keep the same name,surname and email and just change the score.

Can someone help me, thanks.

1
  • 1
    Show us what you have already got. Commented Jan 11, 2012 at 12:00

2 Answers 2

3

first of all create a class User

  class User{
  String name;
  String Email;
  int Score; 
  // bla bla bla
  }

store your users objects in a HashMap

HashMap<int,User> map=new HashMap<int,User>();
User u1=new User();
map.put(1,u1);

and update the object in the map

Integer x=3;
if(map.containsKey(x)){
User u=map.get(x);
u.score=0;
map.put(x,u);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Why dont you create a new class whch has attributes("name", "surname", "id", "email", "score") and afterwards you can get the index that you want if(myarr[i].ID == 1234) and then you can update that index or get the items and equal them to new Class object then delete that item in the required index and then put that index new object again?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.