Thursday, 14 December 2017

Remove All Whitespaces

Program to Remove All Whitespaces



Program:

public class Whitespaces {

    public static void main(String[] args) {
        String sentence = "T    his is e ngin eer siq";
        System.out.println("Original sentence: " + sentence);

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


OUTPUT:


Original sentence: T    his is e ngin eer siq
After replacement: Thisisengineersiq.

No comments:

Post a Comment