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);
    }
}

Comments

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

    ReplyDelete

Post a Comment

Popular posts from this blog

Print Number Pattern - 10 | Java Programs

Print your name in Java | Java Programs

Print Number Pattern - 9 | Java Programs