Eclipse Collections,前置不可变列表

Eclipse Collections, prepend immutable list

如何将(理想情况下 O(1))添加到(Eclipse 集合的)不可变列表中

目前在 Eclipse Collections 中没有可以使用 o(1) 行为添加到前面的 ImmutableList,但是您可以使用 ImmutableStack 来实现类似的行为,具体取决于您的行为正在努力。

ImmutableStack<Integer> stack = Stacks.immutable.empty();
stack = stack.push(1);
stack = stack.push(2);
stack = stack.push(3);
Assert.assertEquals(Stacks.immutable.with(1, 2, 3), stack);

// Eclipse Collections 10.x
ImmutableList<Integer> list1 = stack.toList().toImmutable();
Assert.assertEquals(Lists.immutable.with(3, 2, 1), list1);

// Eclipse Collections 11.x
ImmutableList<Integer> list2 = stack.toImmutableList();
Assert.assertEquals(Lists.immutable.with(3, 2, 1), list2);