I have two different set of values.First set of values i put in a linkedhashmap and take it using a key.now i need to put and take the second set of values using same key.but both set of value are different and the parameters have same name...is it possible?
example: I get three parameters from server namely name,age,class i store it linkedhashmap and take it using name as the key.now iam going to get the second set of values with same parameters name,age,class in the same linkedhashmap..i need to take using the same name as key ..is it possible??
1 Answer 1
You should define an object that has fields for each of the values you intend to store, e.g.:
public class Thing {
private final String name;
private final int age;
private final String cls;
// constructor, getters
}
Then you'd do something like this to add an element to your map:
map.put(name, new Thing(name, age, cls));
You can then get back a particular Thing
by looking it up by name:
Thing found = map.get(name);
-
You've named an instance variable
class
pvg– pvg12/25/2016 08:08:54Commented Dec 25, 2016 at 8:08 -
@pvg thanks, I caught that in the usage example but forgot to fix the class definition. You're welcome to make such trivial edits yourself, btw.dimo414– dimo41412/25/2016 16:17:05Commented Dec 25, 2016 at 16:17
AllValues = <Values1,Values2>
and then put in the map askey: AllValues
pairs