In its simplest form, my game has a counter for a score, and I want that counter to be stored along with a user name that is inputted and sort them from highest to lowest. I would imagine I want to write both attributes to a text file and then when I ask for the leaderboard I can read the text file. How would I go about this?
Asked
Active
Viewed 91 times
1
-
Since you are only using a 2 data point collection I would create a class for the data a linked list for the collection and be able to use the standard library Collections sort functionality unless you are dealing with 10,000 plus players this should easily be able to handle what you need and not even take that much comp time to get it done. – David Coler Oct 16 '18 at 21:12
1 Answers
0
For structuring your data in memory, a HashMap
would work well. A Map
is a collection of key-value pairs. Use the username as the key and the score as the value. Sort the HashMap
on the score.

Grant Foster
- 722
- 2
- 11
- 21