logo

Java String Trim() Method


Show

Description

string. trim()is a built-in function that terminates pioneer and trailing spaces. The Unicode character of the space character is '\u0020'. The trim() process in java checks this Unicode value before and after the string, if it lives then removes the spaces and revisits the omitted string.

Syntax

Here is the syntax of this method:

public String trim()

Parameters

Here is the detail of parameters:

  • NA

Return Value

  • It returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

Example

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("   Welcome to Intellinuts.com   ");

      System.out.print("Return Value :" );
      System.out.println(Str.trim() );
   }
}

This will produce the following result:

Output

Return Value :Welcome to Intellinuts.com

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.