public static Object [ ] add ( Object [ ] list , int startIdx , Object element ) { requireNotNull ( element ) ; // make sure we've got a list to work with if ( list == null ) { list = new Object [ DEFAULT_LIST_SIZE ] ; } // search for a spot to insert yon element; assuming we'll insert // it at the end of the list if we don't find one int llength = list . length ; int index = llength ; for ( int i = startIdx ; i < llength ; i ++ ) { if ( list [ i ] == null ) { index = i ; break ; } } // expand the list if necessary if ( index >= llength ) { list = accomodate ( list , index ) ; } // stick the element on in list [ index ] = element ; return list ; }
Adds the specified element to the next empty slot in the specified list . Begins searching for empty slots at the specified index . This can be used to quickly add elements to a list that preserves consecutivity by calling it with the size of the list as the first index to check .