public static String [ ] trim ( String [ ] array ) { int from = 0 ; int to = 0 ; // test start for ( int i = 0 ; i < array . length ; i ++ ) { from = i ; if ( array [ i ] . length ( ) != 0 ) break ; } // test end for ( int i = array . length - 1 ; i >= 0 ; i -- ) { to = i ; if ( array [ i ] . length ( ) != 0 ) break ; } int newLen = to - from + 1 ; if ( newLen < array . length ) { String [ ] rtn = new String [ newLen ] ; System . arraycopy ( array , from , rtn , 0 , newLen ) ; return rtn ; } return array ; }
trims a string array removes all empty array positions at the start and the end of the array