code: public void insertSorted(T value) {
      add(value);
      @SuppressWarnings("unchecked")
      Comparable<T> cmp = (Comparable<T>) value;
      for (int i = size() - 1; i > 0 && cmp.compareTo(get(i - 1)) < 0; i--) {
        Collections.swap(this, i, i - 1);
      }
    }
docs: Inserts an element and sorts the array.
  
  @param value the value to insert.