Java String.trim()

Syntax

String.trim() has the following syntax.

public String trim()

Example

In the following code shows how to use String.trim() method.


//from  w ww  .  j  a va  2s . c  om
public class Main {
  public static void main(String[] argv) {
    String str = "     java 2 s.com    ";
    System.out.println(">"+str+"<");
    str = str.trim();
    System.out.println(">"+str+"<");
  }
}
  

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable