java - Why doesn't add method accept my inputs? -
so far problematic code, assume else made , done:
public gamerecord[] updatehighscorerecords(gamerecord[] highscorerecords, string name, int level, int score) { // write code after line int = 0; (gamerecord gr : highscorerecords){ if (gr.getscore() >= gr.getscore()){ highscorerecords.add(i+(gr.getlevel()-level),(object) new gamerecord(name, level, score)); /* *adds new gamerecord in @ (i+gr's level - level)th iteration. *note because of assumtion highscorerecords ordered becuase of using function */ break; //no more need continue loop } += 1; } return highscorerecords; }
as may have noticed, code part of course, why i'm assuming other implementations perfect.
you passing in gamerecord[] highscorerecords
array,
but calling list method add
- not exist on array
. should getting compile error.
if sure array has capacity insertion do
highscorerecords[i+(gr.getlevel()-level)] = new gamerecord(name, level, score);
but guess better off using list
arraylist
, , keeping existing code. pass list method not array.
Comments
Post a Comment