Google の ImmutableList クラスを使用していますhttp://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html
既存の ImmutableList と追加の要素 (同じ型) を取り、古い要素と新しい要素を含む新しいImmutableList を返すメソッドを探しています。
おそらく、ドキュメントに明らかな何かが欠けていますか?
Google の ImmutableList クラスを使用していますhttp://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html
既存の ImmutableList と追加の要素 (同じ型) を取り、古い要素と新しい要素を含む新しいImmutableList を返すメソッドを探しています。
おそらく、ドキュメントに明らかな何かが欠けていますか?
public static final ImmutableList<Foo> result
= new ImmutableList.Builder<Foo>()
.addAll(originalList)
.add(new Foo())
.build();
次の方法で実行できます。
ImmutableList<YourType> newList = ImmutableList.copyOf(
Iterables.concat(existingList, ImmutableList.of(newElement))
);
編集: @JB Nizetsソリューションはより読みやすく見えます:)