【发布时间】:2021-06-06 00:38:21
【问题描述】:
有人可以指导我如何使用 Java 8 实现以下目标。我不知道如何将计数器作为键
String str = "abcd";
Map<Integer,String> map = new HashMap<>();
String[] strings = str.split("");
int count =0;
for(String s:strings){
map.put(count++, s);// I want the counter as the key
}
【问题讨论】:
-
您最好寻找
Map<Integer, Character>访问,这又是主要通过String.charAt访问的。如果您可以分享详细信息,构建此地图的用例是什么?