View RSS Feed

Algorithm and Data Structure

Removing Elements from Map

Rate this Entry
by , 02-19-2012 at 07:36 AM (518 Views)
From Map, the removal of elements is done by using remove (Object key) method. This would be removing pair (Key, Value) from Map.

Any type of elements could be put into Map. Type of objects can be limited to be used for values or keys in a Map. How to limit values or keys is well explained in the given code.
Java Code: This is the code to limit values or keys
Map<String, MyObject> map = new HashSet<String, MyObject>();
Map just accepts the value son MyObject type or keys of string type, as it is given above. MyObject might be the customized implementation. In such cases, iteration of values and keys is done without casting.
This process is explained by this code.
Java Code: This is the code to expain map iteration
for(MyObject anObject : map.values()){
   //do someting to anObject...
}
for(String key : map.keySet()){
   MyObject value = map.get(key);
   //do something to value
}

Submit "Removing Elements from Map" to Facebook Submit "Removing Elements from Map" to Digg Submit "Removing Elements from Map" to del.icio.us Submit "Removing Elements from Map" to StumbleUpon Submit "Removing Elements from Map" to Google

Categories
Hashmap

Comments