Here you can find the source of minimiseSpaces(String input)
public static String minimiseSpaces(String input)
//package com.java2s; //License from project: Open Source License public class Main { public static String minimiseSpaces(String input) { return repeatedlyReplace(input, " ", " "); }/* w w w .j a v a 2 s .co m*/ /** * Keep replacing the given string until they are all gone - a multi-pass rather than * the normal single pass of replaceAll * * @param string * @param doomed * @param newbie * @return The string with all the doomed strings replaced with the newbie strings */ public static String repeatedlyReplace(String string, String doomed, String newbie) { String cleaned = string.replaceAll(doomed, newbie); while (cleaned.length() != string.length()) { string = cleaned; cleaned = string.replaceAll(doomed, newbie); } return cleaned; } }