I creating Java project with customers that are Registering and than login in to the system.
I have my setters and getters which are in class Setting
String password, name, lastname;
//getters and setters here
Than in a class Interface I create the HashMap
HashMap<String, Setting> mapList = new HashMap<String, Setting>();
//String is the Key Login and the values is the class with getters and setters
When I call method to put values in to HashMap
mapList.put(Login, password, name, lastname);
//I'm getting error saying that this types of values can not be stored in HashMap
Can any one help me with this problem ?
Ok, so I got solution for this problem for any that has the similar scenario.
When I used method put to add data in to hashmap it didn't store password, name and lastname
mapList.put(login, new User(password, name, lastname));
//this is solution for my scenario
Create a class named Setting
public class Setting {
public String password;
public String name;
public String lastname;
}
then create a hashmap as you are doing
HashMap<String, Setting> mapList = new HashMap<String, Setting>();
Not that your hashmap is accepting key as String and object of setting class as Value
So you can put the value into your hashmap as
Setting setting = new Setting();
setting.password = "Your Password";
setting.name= "Your Name";
setting.lastname= "Your Lastname";
mapList.put("login", setting);
Mark as up if it works for you.