trim() Method In Java Example
Chapter:
String Handling
Last Updated:
11-06-2017 14:15:41 UTC
Program:
/* ............... START ............... */
public class JavaTrimExample {
public static void main(String args[]) {
String Str = new String(" Welcome to JavaScan.com ");
System.out.print("Return Value :");
System.out.println(Str.trim());
}
}
/* ............... END ............... */
Output
Return Value :Welcome to JavaScan.com
Notes:
-
trim() method in Java returns a copy of the string, with leading and trailing whitespace omitted.
- Syntax : public String trim().
- The java string trim() method eliminates leading and trailing spaces. The unicode value of space character is '\u0020'. The trim() method in java string checks this unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.
Tags
trim() Method, Java