Theclearoperation does exactly what you think it does: it removes all of the mappings from theMap. TheputAlloperation is theMapanalogue of theCollectioninterface'saddAlloperation. In addition to its obvious use of dumping oneMapinto another, it has a second, more subtle, use. Suppose aMapis used to represent a collection of attribute-value pairs; theputAlloperation, in combination with the standardMapconstructor, 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