【发布时间】:2014-01-12 12:43:36
【问题描述】:
我有Collection<Number>,但我需要Collection<Integer>
我怎样才能安全地转换它?
还有更常见的问题:
如何将Collection<Parent> 转换为Collection<Child>
【问题讨论】:
-
foreach循环或 GuavaCollections2.transform(collection, function)。 -
... 或开始使用 Java 8 Early Access :)
in.stream().map(n->n.intValue()).collect(intoList()); -
Arnaud Denoyelle 我需要在函数中写什么?
-
@gstackoverflow 你需要一个 Guava 函数:docs.guava-libraries.googlecode.com/git/javadoc/com/google/…
-
Arnaud Denoyelle,如果你写代码示例我会很高兴的。
标签: java collections numbers integer