Apache Commons Collections

http://commons.apache.org/proper/commons-collections/userguide.html

1. Utilities

  • SetUtils
  • CollectionUtils 
  • MapUtils

2.Maps

  • Map Iteration
    •   
      IterableMap map = new HashedMap();
      MapIterator it = map.mapIterator();
      while (it.hasNext()) {
        Object key = it.next();
        Object value = it.getValue();
       
        it.setValue(newValue);
      }
  • Ordered Maps
    •   
      OrderedMap map = new LinkedMap();
      map.put("FIVE", "5");
      map.put("SIX", "6");
      map.put("SEVEN", "7");
      map.firstKey();  // returns "FIVE"
      map.nextKey("FIVE");  // returns "SIX"
      map.nextKey("SIX");  // returns "SEVEN"
  • Bidirectional Maps
    •   
      BidiMap bidi = new TreeBidiMap();
      bidi.put("SIX", "6");
      bidi.get("SIX");  // returns "6"
      bidi.getKey("6");  // returns "SIX"
      bidi.removeValue("6");  // removes the mapping
      BidiMap inverse = bidi.inverseBidiMap();  // returns a map with keys and values swapped

3.Bags

Bag bag = new HashBag();
bag.add("ONE", 6);  // add 6 copies of "ONE"
bag.remove("ONE", 2);  // removes 2 copies of "ONE"
bag.getCount("ONE");  // returns 4, the number of copies in the bag (6 - 2)
原文地址:https://www.cnblogs.com/zeng200103/p/3790549.html