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 ...
3 Answers
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());
Comments
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
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);