Theclear
operation does exactly what you think it does: it removes all of the mappings from theMap
. TheputAll
operation is theMap
analogue of theCollection
interface'saddAll
operation. In addition to its obvious use of dumping oneMap
into another, it has a second, more subtle, use. Suppose aMap
is used to represent a collection of attribute-value pairs; theputAll
operation, in combination with the standardMap
constructor, provides a neat way to implement attribute map creation with default values. Here's a static factory method demonstrating this technique:static Map newAttributeMap(Map defaults, Map overrides) { Map result = new HashMap(defaults); result.putAll(overrides); return result; }
A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates) Be in touch with java jazzle or k2java.blogspot.com.
Sunday, March 13, 2011
Bulk operations on map
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment