title: Implement own ArrayList<> without using collections
body: <p>I am trying to implement my own ArrayList without using java collections for practice purposes. At this stage I want to implement two of main methods, add(E) and get(int) tp get the idea. My code is given below. However I encountered few issues:</p>
  
  <ol>
  <li>The line "return (E) myData[index]" issues warning "Type safety: Unchecked cast from Object to E". How can I address that</li>
  <li>The Java 7 implementation of ArrayList.add(T), returns a boolean. Under what circumstances the add() has to return false. Under what logic it return false and when returns true?</li>
  <li>Where can I find the source code of java 7 implementation of ArrayList</li>
  </ol>
  
  <p>PS. Kindly don't just answer question 3 and refer me to the sucrose code for one and two!</p>
  
  <pre><code>import java.util.Arrays;
  
  public class MyArrayList&lt;E&gt;{
      private final int DEFAULT_SIZE=2;
      private Object[] myData = new Object[DEFAULT_SIZE];
      private int actSize=0;
  
      public boolean add(E data){
          if (actSize&gt;=myData.length/2){
              increaseSize();
          }
          myData[actSize++] = data;
          return true;//when can it be false?
      }
  
      private void increaseSize()throws RuntimeException{
          myData = Arrays.copyOf(myData, myData.length*2);
      }
  
      public E get(int index) throws RuntimeException{
          if (index &gt;= actSize){
              throw new IndexOutOfBoundsException(); 
          }
          return (E) myData[index];
      }
  
      public static void main(String[] args) {
          MyArrayList&lt;String&gt; arList = new MyArrayList&lt;&gt;();
          arList.add("Hello");
          arList.add("Bye bye!");
          System.out.println(arList.get(1));// prints Bye bye! which is correct
  
      }
  }
  </code></pre>