返回一个新的ImmutableList,它是一个现有列表以及一个额外的元素 [英] Returning a new ImmutableList that is an existing list plus an extra element

查看:106
本文介绍了返回一个新的ImmutableList,它是一个现有列表以及一个额外的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的ImmutableList类 http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html

I'm using Google's ImmutableList class http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html

我正在寻找一种方法,该方法需要一个现有的ImmutableList和一个额外的元素(相同类型),并返回一个 new ImmutableList,其中包含旧元素和新元素.

I'm looking for a method which takes an existing ImmutableList and an extra element (of the same type), and returns a new ImmutableList that contains the old elements plus the new one.

也许我在文档中缺少明显的东西?

Perhaps I'm missing something obvious in the docs?

推荐答案

public static final ImmutableList<Foo> result
   = new ImmutableList.Builder<Foo>()
       .addAll(originalList)
       .add(new Foo())
       .build();

这篇关于返回一个新的ImmutableList,它是一个现有列表以及一个额外的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆