title: how to convert following program into generic program in java
body: <p>Convert the following into generic program in Java.
  It is array 1 Dimensional program. I am having issue in converting it in generic program. Please help me..!</p>
  
  <pre><code>public class Array1D {
      protected int AS;
      protected Object[] elements;
  
      public Array1D(int initialCapacity) {
          if (initialCapacity &lt; 1) {
              throw new IllegalArgumentException("initialCapacity must be &gt;= 1");
          }
          elements = new Object[initialCapacity];
          AS = initialCapacity;
      }
  
      public Array1D() {
          elements = null;
          AS = 0;
      }
  
      public void create(int initialCapacity) {
          if (initialCapacity &lt; 1) {
              throw new IllegalArgumentException("initialCapacity must be &gt;= 1");
          }
          elements = new Object[initialCapacity];
          AS = initialCapacity;
      }
  
      void checkIndex(int index) {
          if (index &lt; 0 || index &gt;= AS) {
              throw new IndexOutOfBoundsException("index = " + index + "Size = " + AS);
          }
      }
  
      public boolean put(int index, Object theElement) {
          checkIndex(index);
          elements[index] = theElement;
          return true;
      }
  
      public Object get(int index) {
          checkIndex(index);
          return elements[index];
      }
  
      public Object remove(int index) {
          checkIndex(index);
          Object ob = elements[index];
          elements[index] = null;
          return ob;
      }
  
      public int indexOf(Object theElement) {
          for (int i = 0; i &lt; AS; i++) {
              if (elements[i] == theElement) //if(elements[i].equals(theElement))
              {
                  return i;
              }
          }
          return -1;
      }
  
      public int length() {
          return AS;
      }
  
      public Object[] changeLength(int newLength) {
          Object newArray[] = new Object[newLength];
          System.arraycopy(elements, 0, newArray, 0, AS);
          elements = newArray;
          AS = newLength;
          return newArray;
      }
  
      public String toString() {
          StringBuffer s = new StringBuffer("[");
          for (int i = 0; i &lt; AS; i++) {
              if (elements[i] == null) {
                  s.append("__, ");
              } else {
                  s.append(elements[i].toString() + ", ");
              }
          }
          if (AS &gt; 0) {
              s.delete(s.length() - 2, s.length());
          }
          s.append("]");
          return new String(s);
      }
  
  }
  </code></pre>
  
  <p>End of array class.
  This is its runner class.
  I'm passing 8 elements in an array.</p>
  
  <pre><code>public class Runner {
      static Array1D a = new Array1D(8);
  
      public static void main(String[] args) {
          System.out.println("Length of array is:  " + a.length());
          System.out.println("Array: " + a.toString());
  
          System.out.println();
          a.put(0, (Character) 'A');
          System.out.println("'A' Stored at 0, Array: " + a.toString());
          a.put(2, (Character) 'B');
          System.out.println("'B' Stored at 2, Array: " + a.toString());
          a.put(5, (Character) 'C');
          System.out.println("'C' Stored at 3, Array: " + a.toString());
  
          System.out.println();
          System.out.println("Output for get(0) is:  " + a.get(0));
          System.out.println("Output for get(2) is:  " + a.get(2));
          System.out.println("Output for get(6) is:  " + a.get(6));
  
          System.out.println();
          System.out.println("Index of a: " + a.indexOf((Character) 'B'));
          System.out.println("Index of c: " + a.indexOf((Character) 'C'));
          System.out.println("Index of q: " + a.indexOf((Character) 'q'));
  
          System.out.println();
          a.put(0, (Character) 'A');
          System.out.println("'A' Stored at 0, Array: " + a.toString());
          a.put(2, (Character) 'B');
          System.out.println("'B' Stored at 2, Array: " + a.toString());
          a.put(5, (Character) 'C');
          System.out.println("'C' Stored at 3, Array: " + a.toString());
  
          System.out.println();
          System.out.println(a.remove(0) + " removed from 0, Array: " + a.toString());
          System.out.println(a.remove(1) + " removed from 1, Array: " + a.toString());
  
          a.changeLength(10);
  
          System.out.println();
          System.out.println("Length of array is:  " + a.length());
          System.out.println("Array: " + a.toString());
  
          Character ch = 65;
          System.out.println();
          for (int ctr = 0; ctr &lt; a.length(); ctr++) {
              a.put(ctr, ch);
              System.out.println("'" + ch + "'" + " Stored at " + ctr + ", Array: " + a.toString());
              ch++;
          }
      }
  
  }
  </code></pre>
  
  <p>End of runner class.</p>