title: Trying to increase an array size and add a new value
body: <p>This is just for a simple java project. Here's the code. Basically all I'm trying to do is increase the size of this array if it is full and then when the user decides to add a value, increase the size and add the value into the array.</p>
  
  <pre><code>public void increaseSize(){
  
      int[] temp = new int[list.length * 2];
  
      for (int i = 0; i &lt; list.length; i++){
  
          temp[i] = list[i];
  
      }
  
      list = temp;
  
  }
  
  public void addElement(int newVal){
  
      if (c == list.length){
  
          increaseSize();
  
      }
  
      list[c] = newVal;
      c++;
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>import java.util.Scanner;
  public class IntegerListTest{</p>
  
  <pre><code>static IntegerList list = new IntegerList(10);
  
  //-------------------------------------------------------
  // Create a list, then repeatedly print the menu and do what the
  // user asks until they quit
  //-------------------------------------------------------
  public static void main(String[] args)
  {
  
  Scanner input = new Scanner(System.in);
  printMenu();
  int choice = input.nextInt();
  while (choice != 0)
      {
      dispatch(choice);
      printMenu();
      choice = input.nextInt();
      }
  }
  
  //-------------------------------------------------------
  // Do what the menu item calls for
  //-------------------------------------------------------
  public static void dispatch(int choice)
  {
  
  Scanner input1 = new Scanner(System.in);
  int loc;
  switch(choice)
      {
      case 0: 
      System.out.println("Bye!");
      break;
      case 1:
      System.out.println("How big should the list be?");
      int size = input1.nextInt();
      list = new IntegerList(size);
      list.randomize();
      break;
      case 2:
      list.selectionSort();
      break;
      case 3:
      System.out.print("Enter the value to look for: ");
      loc = list.search(input1.nextInt());
      if (loc != -1)
          System.out.println("Found at location " + loc);
      else
          System.out.println("Not in list");
      break;
      case 4:
      list.print();
      break;
      case 5:
      System.out.print("# to add: ");
      int newnum;
      newnum = input1.nextInt();
      list.addElement(newnum);
      default:
      System.out.println("Sorry, invalid choice");
      }
  }
  
  //-------------------------------------------------------
  // Print the user's choices
  //-------------------------------------------------------
  public static void printMenu()
  {
  
  System.out.println("\n   Menu   ");
  System.out.println("   ====");
  System.out.println("0: Quit");
  System.out.println("1: Create a new list (** do this first!! **)");
  System.out.println("2: Sort the list using selection sort");
  System.out.println("3: Find an element in the list using sequential search");
  System.out.println("4: Print the list");
  System.out.println("5: Add an element to the list.");
  System.out.print("\nEnter your choice: ");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>import java.util.Scanner;</p>
  
  <p>public class IntegerList{</p>
  
  <pre><code>private int c;
  int[] list; //values in the list
  
  //-------------------------------------------------------
  //create a list of the given size
  //-------------------------------------------------------
  public IntegerList(int size)
  {
  list = new int[size];
  c = 0;
  }
  
  
  //-------------------------------------------------------
  //fill array with integers between 1 and 100, inclusive
  //-------------------------------------------------------
  public void randomize()
  {
  for (int i=0; i&lt;list.length; i++)
      list[i] = (int)(Math.random() * 100) + 1;
  }
  
  //-------------------------------------------------------
  //print array elements with indices
  //-------------------------------------------------------
  public void print()
  {
  for (int i=0; i&lt;list.length; i++)
      System.out.println(i + ":\t" + list[i]);
  }
  
  //-------------------------------------------------------
  //return the index of the first occurrence of target in the list.
  //return -1 if target does not appear in the list
  //-------------------------------------------------------
  public int search(int target)
  {
  int location = -1;
  for (int i=0; i&lt;list.length &amp;&amp; location == -1; i++)
      if (list[i] == target)
      location = i;
  return location;
  }
  
  //-------------------------------------------------------
  //sort the list into ascending order using the selection sort algorithm
  //-------------------------------------------------------
  public void selectionSort()
  {
  int minIndex;
  for (int i=0; i &lt; list.length-1; i++)
      {
      //find smallest element in list starting at location i
      minIndex = i;
      for (int j = i+1; j &lt; list.length; j++)
          if (list[j] &lt; list[minIndex])
              minIndex = j;
  
      //swap list[i] with smallest element
      int temp = list[i];
      list[i] = list[minIndex];
      list[minIndex] = temp;
      }
  }
  
  public void increaseSize(){
  
      int[] temp = new int[list.length * 2];
  
      for (int i = 0; i &lt; list.length; i++){
  
          temp[i] = list[i];
  
      }
  
      list = temp;
  
  }
  
  public void addElement(int newVal){
  
      if (c == list.length){
  
          increaseSize();
  
      }
  
      list[c] = newVal;
      c++;
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So basically when I use the option to add a value I expect it to be added onto the end.</p>
  
  <p>Ie.  1,3,4 is the original. If I input 6 I want 6 to be at the end of 1,3,4,6. Right now if I enter 6 it becomes 1,3,6</p>