public
void putAll(Map<? extends K, ? extends V> map)
Copies
all of the mappings from the specified map to this map.
import java.util.*; class TreeMapPutAll{ public static void main(String args[]){ TreeMap<Integer, String> myMap; Map<Integer, String> map; myMap = new TreeMap<> (); map = new HashMap<> (); /* Insert data to myMap */ map.put(1, "w"); map.put(2, "wx"); map.put(3, "wxy"); map.put(4, "wxy"); myMap.putAll(map); System.out.println("Elements in myMap are"); System.out.println(myMap); } }
Output
Elements in myMap are {1=w, 2=wx, 3=wxy, 4=wxy}
1. Throws
NullPointerException if the specified map is null or the specified
map contains a null key and this map does not permit null keys.
No comments:
Post a Comment