Strip
The strip( ) method of String is used to remove the leading and trailing white spaces in the string . For example:
StripLeading
The stripLeading( ) method of String is used to remove the leading white spaces in the string. For example:
StripTrailing
The stripTrailing( ) method of String is used to remove the trailing white spaces in the string. For example:
Program
Program Source
public class Javaapp { public static void main(String[] args) { String str = " ABCD EFGH IJKL "; System.out.println("--"+str+"--"); System.out.println("--"+str.strip()+"--"); System.out.println("--"+str.stripLeading()+"--"); System.out.println("--"+str.stripTrailing()+"--"); } }