title: How to convert ArrayList<String> to int[] in Java
body: <p>I read Bert Bates and Katie Sierra's book Java and have a problem.</p>
  
  <blockquote>
    <p><strong>The Task:</strong> to make the game "Battleship" with 3 classes via using ArrayList.</p>
    
    <p><strong>Error:</strong> the method setLocationCells(ArrayList &lt; String >) in the type
    SimpleDotCom is not applicable for the arguments (int[])</p>
  </blockquote>
  
  <p>I understand that ArrayList only will hold objects and never primatives. So handing over the list of locations (which are int's) to the ArrayList won't work because they are primatives. But how can I fix it?</p>
  
  <p><em>Code:</em></p>
  
  <pre><code>public class SimpleDotComTestDrive {
  
      public static void main(String[] args) {
  
          int numOfGuesses = 0;
  
          GameHelper helper = new GameHelper();
  
          SimpleDotCom theDotCom = new SimpleDotCom();
  
          int randomNum = (int) (Math.random() * 5);
  
           int[] locations = {randomNum, randomNum+1, randomNum+2};
  
           theDotCom.setLocationCells(locations);
  
          boolean isAlive = true;
  
          while(isAlive) {    
  
              String guess = helper.getUserInput("Enter the number");
  
              String result = theDotCom.checkYourself(guess);
  
              numOfGuesses++;
  
              if (result.equals("Kill")) {
                  isAlive = false;
                  System.out.println("You took " + numOfGuesses + "  guesses");
              }
          }
      }
  }
  
  public class SimpleDotCom {
  
      private ArrayList&lt;String&gt; locationCells;
  
      public void setLocationCells(ArrayList&lt;String&gt; loc) {
          locationCells = loc;
      }
  
      public String checkYourself(String stringGuess) {
  
          String result = "Miss";
  
          int index = locationCells.indexOf(stringGuess);
  
          if (index &gt;= 0) {
              locationCells.remove(index);
  
              if(locationCells.isEmpty()) {
                  result = "Kill";
              } else {
                  result = "Hit";
              }
          }
          return result;
      }
  }
  
  public class GameHelper {
  
      public String getUserInput(String prompt) {
          String inputLine = null;
          System.out.print(prompt + " ");
          try {
              BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
              inputLine = is.readLine();
              if (inputLine.length() == 0)
                  return null;
          } catch (IOException e) {
              System.out.println("IOException:" + e);
          }
          return inputLine;
      }
  }
  </code></pre>