title: How do I add a parameter to the end of an array?
body: <p>I am working on this NumberList class which represents a list of integers.  The NumberList object has just one instance variable, which is a reference to an array of int values.  One of the methods I need to implement is suppose to add the parameter to the end of the list by:</p>
  
  <p>a) creating another array that is one unit larger than the existing one</p>
  
  <p>b) Copying all of the elements from the existing array over to the new one</p>
  
  <p>c) Adding the parameter to the end of the new array</p>
  
  <p>d) Re-assigning the instance variable "values" so that it refers to the new array.</p>
  
  <p>Here is my attempt at it.  There are no errors but I feel like it is incorrect especially the part where I try to add number to the end of anotherArray.  The parameter I am referring to is "number", an int</p>
  
  <pre><code>public void add(int number) {
      int[] anotherArray;
      int newLength = values.length + 1;
  
      anotherArray = new int[newLength];
  
      for (int i = 0; i &lt;values.length; i++)
          values[i] = anotherArray[i];
  
      for (int i = 0; i &lt; anotherArray[i]; i++)
          anotherArray[i] += number;
  
  
  
      values = new int[anotherArray.length];
  }
  </code></pre>