import java.util.HashMap;
import java.util.Map;
class Solution {
public static void main(String[] args)
{
Map<Integer, String> myFavoriteColours = new HashMap<>();
Map<Integer, String> myFriendsFavoriteColours = new HashMap<>();
myFavoriteColours.put(1, "Purple");
myFavoriteColours.put(2, "Yellow");
myFavoriteColours.put(3, "Black");
System.out.println("Values in first map: " + myFavoriteColours);
myFriendsFavoriteColours.put(4, "White");
myFriendsFavoriteColours.put(5, "Silver");
myFriendsFavoriteColours.put(6, "Orange");
System.out.println("Values in second map: " + myFriendsFavoriteColours);
Map<Object, Object> ourFavoriteColours = new HashMap<>();
ourFavoriteColours.put(myFavoriteColours);
ourFavoriteColours.put(myFriendsFavoriteColours);
System.out.println("Values in third map: " + ourFavoriteColours);
}
}
:24:27
java: method put in interface java.util.Map<K,V> cannot be applied to given types;
required: java.lang.Object,java.lang.Object
found: java.util.Map<java.lang.Integer,java.lang.String>
reason: actual and formal argument lists differ in length
i don't know how to put two maps into new one Merging map a with b into c how to do ?
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Karol Grzeszczak
29 May 2022, 17:46
I did it like this but I don't know if it's the correct solution
0
Lisa L
30 May 2022, 19:42
how should the result in the 3rd map look like? do you just want to put all elements of the first two maps into the third (so that you have 6 elements there) or do you 'really' want to merge the elements. So that the third map has three elements that are the result of some calculation of the elements of the first and second map?
0