title: How to use Java Dynamic Array
body: <p>I am currently taking a Java Programming class and we are on the topic of dynamic arrays.  We were asked to write a program using dynamic arrays that would print out the Fibonacci Sequence.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>public class Fibonacci {
      private static int[] data;
  
      public static void DynamicArray() {
          data = new int[1];
      }
  
      public static int get(int position) {
          if (position &gt;= data.length){
              return 0;
          } else {
              return data[position];
          }
      }
  
      public static void put(int position, int value) {
          if(position &gt;= data.length) {
              int newSize = 2 * position;
              int[] newData = new int[newSize];
              System.arraycopy(data, 0, newData, 0, data.length);
              data = newData;
          }
          data[position] = value;
      }
  
      public static void main(String[] args) {
          System.out.println("\nFibonacci Sequence:\n");
          System.out.println(data[0]);
          for(int i = 2; i&lt; = 20; i++) {
              data[i] = data[i-1] + data[i-2];
              System.out.println(data[i]);
          }
      }
  }
  </code></pre>
  
  <p>Thanks!</p>