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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -