【发布时间】:2016-02-01 13:25:34
【问题描述】:
有没有简单的方法在java 8中使用lambda进行转换
来自这个对象:
"coords" : [ {
"x" : -73.72573187081096,
"y" : 40.71033050649526
}, {
"x" : -73.724263,
"y" : 40.709908}
]
到这个对象:
"coordinates":[
[
[
-73.72573187081096,
40.71033050649526
],
[
-73.724263,
40.709908
]]
我尝试使用transform() 函数,但如何从列表转换为二维数组?
这是我的尝试, 但我得到了一个错误:
coordinates =
Lists.newArrayList(
Lists.newArrayList(
Lists.newArrayList(
coords.stream()
.map( item -> Lists.newArrayList(ImmutableList.of(item.x, item.y))))));
【问题讨论】: