public static List < String > split ( String string , String separator ) { final int separatorLength = separator . length ( ) ; final List < String > list = new ArrayList < String > ( ) ; int fromIndex = 0 ; for ( ; ; ) { int endIndex = string . indexOf ( separator , fromIndex ) ; if ( endIndex == - 1 ) { break ; } if ( fromIndex < endIndex ) { list . add ( string . substring ( fromIndex , endIndex ) . trim ( ) ) ; } fromIndex = endIndex + separatorLength ; } if ( fromIndex < string . length ( ) ) { list . add ( string . substring ( fromIndex ) . trim ( ) ) ; } return list ; }
Splits string using specified string separator and returns trimmed values . Returns null if string argument is null and empty list if is empty .