0

I am trying to one user id and store multiple values like firstname , lastname, city etc... but at same time again store same user id and same value gate so how to store only one time not store duplicate record any one please help me and give me more details please friend ...

0

3 Answers 3

1

you can create a JAVA bean class that consists of all the required data. like :

class Data{
    private String firstName;

    private String lastName;

    private String city;


    //gettter and setters
}

then you can store that bean against a userId in a collection Map. like :

Map<String, Data> map=new HashMap<>();

map.put("12345",new Data());
Sign up to request clarification or add additional context in comments.

Comments

1

You should have some Map object something like

 Map<String, CustomObject> myMap;

then add the user as follows:

 if(null == myMap.get(userId))
   myMap.put(userId, custObj);

Your custom object would be like

 public class CustomObject{
    private String fname;
    private String sname;
    // more fields and getter setters
 }

Comments

1

Create an class User-

class User{
   int id;
   String firstName;
   String lastname;
   String city;
   ......
}  

Now create a Map -

Map<Integer, User> userMap = new HashMap<Integer, User>();

Now you can save User with id like this -

user1 = new User(id, firstName, lastName, city ...)
userMap.put(1, user1);

user2 = new User(id, firstName, lastName, city ...)
userMap.put(2, user2);

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.