更新时间:2023-10-05 15:32:52
您可以使用 IntStream
创建 Stream
的索引,然后将它们转换为a Map
:
You can create a Stream
of the indices using an IntStream
and then convert them to a Map
:
Map<Integer,Item> map =
IntStream.range(0,items.size())
.boxed()
.collect(Collectors.toMap (i -> i, i -> items.get(i)));