gpt4 book ai didi

Java 集合引用-副本

转载 作者:行者123 更新时间:2023-12-02 00:52:47 24 4
gpt4 key购买 nike

是否有一个集合的标准 Java(1.5+)实现(即无第三方),允许我将多个集合粘合到一个集合中?

这是其工作原理的草图:

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.

谢谢!

最佳答案

没有一个标准集合可以使用您所追求的语义来嵌套集合。

关于Java 集合引用-副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2323265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com