How to remove Whitespaces from String

How to remove Whitespaces from String

Example:

Input:  str ="  Hello World!!  "
Output: Remove All white space:HelloWorld!!

Approach

Java


public class HelloWorld {
    public static void main(String[] args) {
        String str = "  Hello World!!  ";
        str = str.replaceAll("\\s""");
        System.out.println("Remove All white space:" + str);
    }
}


No comments:

Post a Comment