I'm new to Java and to this forum and I hope you can help me out; I'm working in Android Studio and I would like to keep and display a Top 5 highScore list in my application.
For everytime someone finish the game I get the score and firstname of the player;
private void saveScore(){
String firstname = mPreferences.getString(PREF_KEY_FIRSTNAME, null);
int score =mPreferences.getInt(PREF_KEY_SCORE, 0);
//add name and score to map and save in shared preferences
Map<String,Integer> highScores=new HashMap<>();
highScores.put(firstname, score);
for (String s : highScores.keySet()) {
prefHighscore.edit().putInt(s, highScores.get(s));
}
prefHighscore.edit().apply();
}
I then want to access the map in my ScoreActivity private void getScores() {
HashMap<String, Integer> map= (HashMap<String, Integer>)
prefHighscore.getAll();
for (String s : map.keySet()) {
Integer value = map.get(s);
}
I hope this code is allright. I now get stuck because I would like to:
1.sort the list and get five highscores. 2.get the name and score for the five and display them
Can you give me some hints?