public static String deleteExcededSpaces ( String text ) { int size = text . length ( ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < size ; i ++ ) { char ch = text . charAt ( i ) ; if ( ch == ' ' ) { if ( i > 0 ) { char ch2 = text . charAt ( i - 1 ) ; if ( ( ch2 != ' ' ) && ( i < size - 1 ) && ( ! text . substring ( i + 1 ) . trim ( ) . equals ( "" ) ) ) { sb . append ( ch ) ; } } } else { sb . append ( ch ) ; } } return sb . toString ( ) ; }
Only one space between words .