public static String getAt ( String list , char delimiter , int position , boolean ignoreEmpty , String defaultValue ) { int len = list . length ( ) ; if ( len == 0 ) return defaultValue ; int last = - 1 ; int count = - 1 ; for ( int i = 0 ; i < len ; i ++ ) { // char == delimiter if ( list . charAt ( i ) == delimiter ) { if ( ignoreEmpty && ( last + 1 ) == i ) { last = i ; continue ; } count ++ ; if ( count == position ) { return list . substring ( last + 1 , i ) ; } last = i ; } } if ( position == count + 1 ) { if ( ! ignoreEmpty || last + 1 < len ) return list . substring ( last + 1 ) ; } return defaultValue ; }
get a elemnt at a specified position in list