title: how can i save player name and score in my java game?
body: <p>i am making my first android game.i want to save the user name and score to a file and read it later.i am trying to use arraylist to store 5 user objects.I don't know how to write efficiently to the file and read it back and store in arraylist. if you know another beter way please tell me.
  here is the method I am using to write.</p>
  
  <pre><code>public static void save(FileIO file) {
      preferences = file.getSharedPref();
      Editor editor = preferences.edit();
      for(int i=0;i&lt;5;i++){
          editor.putString("username"+String.valueOf(i), User.userList.get(i).userName);
          editor.putInt("userscore"+String.valueOf(i), User.userList.get(i).highScore);
          }
      editor.commit();
  }
  </code></pre>
  
  <p>And this is the method I am using to read.</p>
  
  <pre><code>public static void read(FileIO file) {
      preferences = file.getSharedPref();
      for(int i=0;i&lt;5;i++){
          User.userList.get(i).userName=preferences.getString("username"+String.valueOf(i), "abc");
          User.userList.get(i).highScore=preferences.getInt("userscore"+String.valueOf(i), 0);
      }
  
  }
  </code></pre>
  
  <p>And this is the loop I am trying to display my highscore.
  <code>for(int i=0;i&lt;5;i++){
                       g.drawString(String.valueOf(i+1)+"."+String.valueOf(User.userList.get(i).userName), 100, y, paint);
                      g.drawString(String.valueOf(User.userList.get(i).highScore),150, y, paint2);
                      y+=80;
          }</code></p>
  
  <p>i am getting indexoutofbounds exception</p>