I've got a JTable which shows the top 10 scores of a game. The data structure looks like the following:
// {Position, Name, Score}
Object[][] data = {
{1, "-", 0},
{2, "-", 0},
{3, "-", 0},
{4, "-", 0},
{5, "-", 0},
{6, "-", 0},
{7, "-", 0},
{8, "-", 0},
{9, "-", 0},
{10, "-", 0}
};
I want to be able to add a new score to this array in the correct order (so if it was the 3rd highest, it would be put at index 2). I'll then truncate this list down to the top 10 again and update the table.
I know this is trivial to do by looping through and checking, but I'd like to know if there is an appropriate data structure that is better suited for data ordered by a value? Or is the simple two-dimensional array the only/best?