Trim Whitespaces From A String | Java Programs

Output:

*** Trim Any Spaces From String ***

Original String:                   Java Exercises
New String: Java Exercises

Click Here For Java Online Compiler

Solution:

public class TrimString {

    public static void main(String[] args) {
        System.out.println("*** Trim Any Spaces From String ***" + "\n");
        String string = "                  Java Exercises";

        // Trim the whitespace from the front of the String.
        String newString = string.trim();

        // Display the strings for comparison.
        System.out.println("Original String: " + string);
        System.out.println("New String: " + newString);
    }
}
Share This :

Related Post

avatar

nice article in your blog.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:18



sentiment_satisfied Emoticon