Search in sources :

Example 1 with HashBag

use of org.apache.commons.collections.HashBag in project pancm_project by xuwujing.

the class collectionsTest method bagTest.

/**
 * Bag 测试
 * 主要测试重复元素的统计
 */
@SuppressWarnings("deprecation")
private static void bagTest() {
    // 定义4种球
    Bag box = new HashBag(Arrays.asList("red", "blue", "black", "green"));
    // box.getCount():1
    System.out.println("box.getCount():" + box.getCount("red"));
    // 红色的球增加五个
    box.add("red", 5);
    // box.size():9
    System.out.println("box.size():" + box.size());
    // box.getCount():6
    System.out.println("box.getCount():" + box.getCount("red"));
}
Also used : HashBag(org.apache.commons.collections.HashBag) HashBag(org.apache.commons.collections.HashBag) Bag(org.apache.commons.collections.Bag)

Example 2 with HashBag

use of org.apache.commons.collections.HashBag in project pancm_project by xuwujing.

the class commonsTest method bagTest.

/**
 * Bag 测试
 * 主要测试重复元素的统计
 */
@SuppressWarnings("deprecation")
private static void bagTest() {
    // 定义4种球
    Bag box = new HashBag(Arrays.asList("red", "blue", "black", "green"));
    // box.getCount():1
    System.out.println("box.getCount():" + box.getCount("red"));
    // 红色的球增加五个
    box.add("red", 5);
    // box.size():9
    System.out.println("box.size():" + box.size());
    // box.getCount():6
    System.out.println("box.getCount():" + box.getCount("red"));
}
Also used : HashBag(org.apache.commons.collections.HashBag) HashBag(org.apache.commons.collections.HashBag) Bag(org.apache.commons.collections.Bag)

Aggregations

Bag (org.apache.commons.collections.Bag)2 HashBag (org.apache.commons.collections.HashBag)2