/** * @author lautturi.com * Java example: java replace all single characters in string */ import java.util.*; public class Lautturi { public static void main(String[] args) { String str = "welcom to java world. Java is a high-level programming language."; System.out.println(str); str = str.replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim(); System.out.println(str); } }Socrue:www.lautturi.com
output:
welcom to java world. Java is a high-level programming language. welcom to java world. Java is high-level programming language.