Here you can find the source of minimizeWhitespace(String str)
public static String minimizeWhitespace(String str)
//package com.java2s; //License from project: LGPL public class Main { public static Object minimizeWhitespace(Object o) { return minimizeWhitespace(String.valueOf(o)); }//from w w w.ja v a 2 s. c o m public static String minimizeWhitespace(String str) { str = str.trim(); StringBuilder buff = new StringBuilder(); int len = str.length(); boolean lastWasNonWhite = true; for (int i = 0; i < len; ++i) { char c = str.charAt(i); if (Character.isWhitespace(c)) { if (lastWasNonWhite) { lastWasNonWhite = false; buff.append(' '); } } else { lastWasNonWhite = true; buff.append(c); } } return buff.toString(); } }