我有方法,它返回 java.util.Collection
我想用 Iterables.find
我该怎么做?
我有
Collections2<Integer>
我敢打赌你不会。您不能实例化Collections2
(除了反射),即使您实例化了,也没有参数化。
因此我想将其转换为
Iterables<Integer>
假设您的意思是Iterable<Integer>
,此行应执行以下操作:
Iterable<Integer> = yourIntegerList;
如果你想使用Iterables
一个List
,只要做到这一点:
Iterables.contains(yourIntegerList, 2)
但是,List
s有一个古老的简单方法:只需执行yourIntegerList.contains(2)
。
没什么变化,每个也Collection
都是一个Iterable
。
去做就对了。如果您遇到错误,请向我们显示。否则,我们唯一了解的是您目前对层次结构感到困惑。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句