java tutorial - Java strings trim() method - java programming - learn java - java basics - java for beginners



Java strings trim

Learn Java - Java tutorial - Java strings trim - Java examples - Java programs

Description

The trim () method — returns a copy of the line with missing leading and trailing spaces, in other words, the method allows in Java to remove spaces at the beginning and end of the line.

Syntax

Syntax of this method:

public String trim()
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • No.

Return value

  • In Java, trim () returns a copy of this line, in which the leading and trailing spaces are removed, or this line if it does not have leading or trailing spaces.

Sample Code

import java.io.*;

public class Test {

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

      System.out.print("Return value:" );
      System.out.println(Str.trim ());
   }
}
click below button to copy the code. By - java tutorial - team

Output

Return value:Welcome to wikitechy.com

Related Searches to Java strings trim() method