是否有一個標準的Java(1.5+)實現(即沒有第三方)的集合允許我將多個集合合併爲一個?Java collection reference-copy
這裏是一個草圖,它是如何工作:
final SomeCollection x = new SomeCollection();
final ArrayList a = new ArrayList();
a.add("first");
assert(a.size() == 1);
x.embed(a); // don't know for sure, if this exists.
assert(x.size() == 1);
a.add("second");
assert(a.size() == 2);
assert(x.size() == 2); // the other array is used as a backend-collection.
final ArrayList b = new ArrayList();
b.add("third");
assert(b.size() == 1);
x.embed(b);
assert(x.size() == 3); // x is a combination of the other two lists.
謝謝!
不是沒有自己實現它。 (一個簡單的「否」不夠長。:) :) – PSpeed 2010-02-24 02:29:45