public int [ ] find ( String str , String search , int fromIndex ) { if ( str == null || search == null ) { return new int [ 0 ] ; } int [ ] indices = new int [ 10 ] ; int size = 0 ; int index = fromIndex ; while ( ( index = str . indexOf ( search , index ) ) >= 0 ) { if ( size >= indices . length ) { // Expand capacity. int [ ] newArray = new int [ indices . length * 2 ] ; System . arraycopy ( indices , 0 , newArray , 0 , indices . length ) ; indices = newArray ; } indices [ size ++ ] = index ; index += search . length ( ) ; } if ( size < indices . length ) { // Trim capacity. int [ ] newArray = new int [ size ] ; System . arraycopy ( indices , 0 , newArray , 0 , size ) ; indices = newArray ; } return indices ; }
Finds the indices for each occurrence of the given search string in the source string starting from the given index .