public boolean addSorted ( E element ) { boolean added = false ; added = super . add ( element ) ; Comparable < E > cmp = ( Comparable < E > ) element ; for ( int i = size ( ) - 1 ; i > 0 && cmp . compareTo ( get ( i - 1 ) ) < 0 ; i -- ) Collections . swap ( this , i , i - 1 ) ; return added ; }
adds an element to the list in its place based on natural order . allows duplicates .