i search a way to copy x element from a map to another.
i tried this code
private void newMapElement( Map<?, ?> userMap, Map<?, ?> newUserMap, int maxSize)
{
int i = 0;
for ( Map.Entry<?, ?> entry : userMap.entrySet() )
{
newUserMap.put( entry.getKey(), entry.getValue() );
i++;
if ( i == maxSize)
{
break;
}
}
}
but java don’t seem to like the put.
Any idea?
you have to use
? super Tfor newUserMap as wildcards with super(wildcards with upperbounds) would allow you to add elements into your map,your code should be something like below: