腾讯网站的品牌建设计划,网站备案一般由谁来做,关键词优化工具互点,wordpress搬家后页面和分类打不开使用像TreeMap这样的有序集合#xff0c;它按照键的自然顺序保存其条目(键值映射)。因为#xff0c;您希望对高分进行排序#xff0c;将分数作为键和玩家名称作为其值。// instantiate your sorted collectionMap highestScores new TreeMap();// setup a file readerBuffe…使用像TreeMap这样的有序集合它按照键的自然顺序保存其条目(键值映射)。因为您希望对高分进行排序将分数作为键和玩家名称作为其值。// instantiate your sorted collectionMap highestScores new TreeMap();// setup a file readerBufferedReader reader new BufferedReader(new FileReader(new File(/path/to/file)));String line null;while ((line reader.readLine()) ! null) { // read your file line by lineString[] playerScores line.split(: );// populate your collection with score-player mappingshighestScores.put(Integer.valueOf(playerScores[1]), playerScores[0]);}// iterate in descending orderfor (Integer score : highestScores.descendingKeySet()) {System.out.println(highestScores.get(score) : score);}的输出强的Eric: 25Oscar: 18Bert: 16John: 12Carl: 9修改强两个或更多玩家很可能拥有相同的高分。因此排序后的集合必须更加复杂但如果您已经理解了上面的那个那么理解这个集合就不会有麻烦了。现在我们不得不将得分映射到玩家我们必须将其映射到List个玩家(具有相同的高分)// {key - value} {high score - {list, of, players}}TreeMap highestScores new TreeMap();BufferedReader reader new BufferedReader(new FileReader(new File(/path/to/file)));String line null;while ((line reader.readLine()) ! null) {String[] playerScores line.split(: );Integer score Integer.valueOf(playerScores[1]);List playerList null;// check if a player with this score already existsif ((playerList highestScores.get(score)) null) { // if NOT,playerList new ArrayList(1); // CREATE a new listplayerList.add(playerScores[0]);highestScores.put(Integer.valueOf(playerScores[1]), playerList);} else { // if YES, ADD to the existing listplayerList.add(playerScores[0]);}}// iterate in descending orderfor (Integer score : highestScores.descendingKeySet()) {for (String player : highestScores.get(score)) { // iterate over player listSystem.out.println(player : score);}}的输出强的Eric: 25Oscar: 18Bert: 16John: 12 *Jane: 12 *Carl: 9