Let’s say I have an object of each class below, and I put each object in a hashmap where IDnumber is the key in both maps.
class1 {
int IDNumber = 123; //same person as class2
String name = John;
String company = Intel;
class2 {
int IDNumber = 123; //same person as class1
int income = 500;
int workYears = 3;
}
HashMap<Integer, class1> one = new Hashmap<Integer, class1>();
HashMap<Integer, class2> two = new HashMap<Integer, class2>();
Now, how can I mash these two HashMaps into a third HashMap so that I can have the key IDnumber, and the values name, company, income, and workyears?
You can not do that. You have two different classes, and java is not going to auto-magically make them one.
You could create a new third class to merge the info:
Then loop through your map to get the entries, creating new Class3 instance for each and place them in a new
HashMap<Integer, Class3>.