Easy Tutorial
❮ Number Max Number Min ❯

Java trim() Method

Java String Class


The trim() method is used to remove the leading and trailing whitespace characters from a string.

Syntax

public String trim()

Parameters

-

None

Return Value

The string with leading and trailing whitespace removed.

Example

public class Test {
    public static void main(String args[]) {
        String Str = new String("    www.tutorialpro.org    ");
        System.out.print("Original value :" );
        System.out.println( Str );

        System.out.print("After trimming :" );
        System.out.println( Str.trim() );
    }
}

The output of the above program is:

Original value :    www.tutorialpro.org    
After trimming :www.tutorialpro.org

Java String Class

❮ Number Max Number Min ❯