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;
}
Saturday, 12 March 2011
Bulk operations on map
Labels:
bulk operations,
Collections,
java,
map
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment