Write a program that will remove extra white space from a string

Method to remove extra white space:
String.trim();

A simple Java program:

public class Main {
    public static void main(String[] args) {
        String s = " Hello Java "; //adding white space before and after string
        System.out.println(s.trim());
    }

}
Output: 
Hello java //after removing white space

about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *