program to remove whitespaces within string

Java program to remove space within given string

public class Whitespaces {

    public static void main(String[] args) {
        String sentence = "T    his is b  ett     er.";
        System.out.println("Original sentence: " + sentence);

        sentence = sentence.replaceAll("\\s", "");
        System.out.println("After replacement: " + sentence);
    }

}

Comments

Popular posts from this blog

Java Variables and Datatype

JAVA Features

Java Fundamentals