title: Adding and deleting elements in ArrayList set as a value in a hashmap
body: <p>So I have a file that looks like this:</p>
  
  <pre><code>    1st 2nd­ nth
      e1­, ­­v1, 1
      e1, v3, 2
      e1, v4, 4
      e1, v5, 7
      e2, v1, 1
      ., ­., .
      ., ­., .
      ., ­., .
  </code></pre>
  
  <p>where I want the first column to be the key of a hashmap (e1, or e2, or e3), and the value to be an ArrayList called "Ratings" that in I want the second column to have it's value (an int), inside the nth index of the arraylist.</p>
  
  <p>Here is my code in it's entirety so far:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Setup
  {
      public static void Setup(String[] args)
      {
          String user;
          int value, location;
          //Create a Hashmap that holds a string key and an ArrayList value
          HashMap&lt;String, ArrayList&lt;Integer&gt;&gt; userRatings = new HashMap&lt;String, ArrayList&lt;Integer&gt;&gt;();
          try
          {
              BufferedReader bufferReader = new BufferedReader(new FileReader("Student list.txt")); //read from file
              String line, sentence; //declare two string variables
              String[] sData; //declare a string array (store the contents here)
              line = bufferReader.readLine(); //Read the line
              while (line != null) //While there is a line, do this:
              {
                  line = bufferReader.readLine();
                  sData  = line.split(", "); //Into the string array, enter individual values in the line split by the ", " characters
                  int iData[] = new int[sData.length]; //Create an int array the size of the string array
                  user = sData[0];
                  for (int i = 0; i &lt;sData.length; i++) //fill the int array with the int-version of the string array
                  {
                      iData[i] = Integer.parseInt(sData[i]); //pass the strings as integers into the integer array
                  }
                  value = iData[1];
                  location = iData[2];
                  if(!userRatings.containsKey(user)) //The user does not have ratings.
                  {
                      ArrayList&lt;Integer&gt; ratings = new ArrayList&lt;Integer&gt;();
                      //                     ratings = userRatings.get(user);
                      for (int j = 0; j &lt; 50; j++)
                      {
                          ratings.add(j);
                      }
                      System.out.println(user + " " + userRatings.get(user));
  
                  }
                  else //The user has ratings
                  {
                      userRatings.get(user).add(location,value);
                      System.out.println(user + " " + userRatings.get(user));
                  }
              }
              bufferReader.close();
          }    catch (FileNotFoundException e)
          {
              System.out.println("File does not exist or could not be found.");
          }
          catch (IOException e)
          {
              System.out.println("Can't read from file");
          }
          catch (NullPointerException e)
          {
          }
      }
  }
  </code></pre>
  
  <p>I am having a problem with modifying the contents of the arraylist.</p>
  
  <p>To sum up:
  Every string in the 1st column of the file would have it's own key in the hashmap (userList)
  The program will check if it has the key, if no key exists, it will create a new arraylist as the value for the key.
  The arrayList will be populated with 50 indexes, of which they will contain "0".
  After that, the arraylist will have new values added from the file in which the integer in the second column will be added at the corresponding value of the nth column.</p>
  
  <p>How would I populate the arraylist, and how would I edit it so that if I want to add a new integer at the nth index of user e6, I could?</p>