鉴于如下的流{ 0, 1, 2, 3, 4 },
我怎样才能最优雅地将其转换为给定的形式:
{ new Pair(0, 1), new Pair(1, 2), new Pair(2, 3), new Pair(3, 4) }
(假设,当然,我已经定义了类对)?
编辑:这不是严格关于整数或原始流.对于任何类型的流,答案应该是通用的.
我一直在用java学习正则表达式.我想知道在使用java的matcher时使用\ G是否有意义.我找不到任何与G一起使用的例子:(:
做这样的事情与使用\ G不会有相同的输出?
String a = "Pruebaprueba";
Matcher matcher = Pattern.compile("(\\w)").matcher(a);
while ( matcher.find() ) {
// Do something with each letter
}
Run Code Online (Sandbox Code Playgroud)
谢谢阅读!