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