我在记住如何填充ArrayList时遇到问题,而我似乎无法找到如何做到这一点。我想用它来保持HighScore。我目前有一个矩阵,它看起来像这样:
if(score>record){
System.out.println("Congrats, high score! Please type your name:");
String name=sc.next();
highScore[1][0] = name;
highScore[0][0] = ("Player");
record=score;
highScore[0][1]=("Current");
highScore[1][1]=(score+"");
highScore[0][2]=("Highest");
highScore[1][2]=(record+"");
}
我想使用一个列表,因为显示将是相同的,我可以添加尽可能多的高分。如果你能告诉我怎么做,或者任何其他方法,那就太棒了。
答案 0 :(得分:0)
As this image points out you allocate data to specific cells of your 2D array:
Assuming that:
highScore[p] is the player and [d] is the data (score, name etc.), then updating a specific players data should always look like this:
player = p;
data = d;
highScore[p][d] = data goes here; //in the above image row = p, column = d!
And updating multiple players could be done using a for loop.
better yet as mentioned in the comments you would be better creating a method and calling it with parameters p and d.
If you want to increase the size of your array that is impossible but you can move all of the data to a new array if it gets to large, is that what you where asking?