Apache Commons Collections

Apache Commons Collections(アパッチ コモンズ・コレクションズ)は、ApacheのトッププロジェクトであるApache Commonsにある、Javaのjava.utilパッケージのCollection関係を拡張するライブラリである。

使用例

Java 6 にはクロージャがないが、Predicate を実装することで、条件を満たす物を探すことができる。以下、リストから、a で始まる物を見つけ出す。

ArrayList<String> list = new ArrayList<String>();
list.add("apple");
list.add("banana");
list.add("ant");
Collection<String> aList = CollectionUtils.select(list, new Predicate<String>() {
    public boolean evaluate(String str) {
        return str.startsWith("a");
    }
});

外部リンク

Uses material from the Wikipedia article Apache Commons Collections, released under the CC BY-SA 4.0 license.