Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * @param str * @return String. */ public static String multiSpace2singleSpace(String str) { Pattern pattern; Matcher matcher; pattern = Pattern.compile("[\\s]+"); matcher = pattern.matcher(str); return matcher.replaceAll(" "); } }