简体   繁体   中英

How do I put an ArrayList<Integer> in a String Variable?

I would like to put an ArrayList and some letters into a String variable in order to display it in a JOptionPane.showMessageDialog yet I dont really know how to do that.

String output = "";
for(int i = 0; i<=l; i++){
   if (i <= 10){
      output += i+1 + ".: "+ highscorelist.get(i)+"%\n";
   }
}

JOptionPane.showMessageDialog(null, "These are the top score:\n"+output);

My String should be "output", l is the amount of Arrayfields I put in the highscorelist. Thanks in advance!

The code should be working, but you have there one mistake. In for and if you have <=, this will loop l + 1 times and it will put 11 records into output variable. Replace it with <.

for(int i = 0; i<l; i++){
    if (i < 10){
    output += i+1 + ".: "+ highscorelist.get(i)+"%\n";
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM