我的hashmap键返回:MemorySection [path =' rr&#39 ;, root =' YamlCofiguration'] = 1
无论如何,我可以获得path =''的价值。我知道我可以获得root =''的价值。使用getValue(),虽然我只是用它来跟踪最高和最低值然后从最高到最低排序。
我已经尝试过这个帖子,虽然答案假设我知道对的名字是什么。 Retrieving Key from the Hash Map
编辑: 以下是我如何设置数据并对其进行排序。我通过likesList List
访问它HashMap<String, Integer> likes = new HashMap<>();
for(String key: playersFile.getKeys(false)) {
likes.put(playersFile.getString(key), playersFile.getInt(key + ".likes"));
}
List<Entry<String, Integer>> likesList = new LinkedList<Entry<String, Integer>>(likes.entrySet());
Collections.sort(likesList, new Comparator<Entry<String, Integer>>() {
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
for (int i = 0; i<45; i++) {
try {
String name1 = cookiesList.get(i).getKey();
item = name(name1);
publicinv.setItem(i, item);
} catch (IndexOutOfBoundsException e) {
}
}
答案 0 :(得分:1)
我仍然不知道你想要什么,但这是我猜的:
// your input
String name1 = "MemorySection[path='rr', root='YamlCofiguration']=1";
// this string indicates the start of the path
String start = "path='";
// where the path starts
int pathStart = name1.indexOf(start)+start.length();
// where the path ends
int pathEnd = name1.substring(pathStart).indexOf("'") + pathStart;
// get the path
System.out.println( name1.substring(pathStart, pathEnd) ); // prints: rr