Strip

Java-Strip

Strip

The strip( ) method of String is used to remove the leading and trailing white spaces in the string . For example:

Strip


StripLeading

The stripLeading( ) method of String is used to remove the leading white spaces in the string. For example:

StripLeading

StripTrailing

The stripTrailing( ) method of String is used to remove the trailing white spaces in the string. For example:

StripTrailing

Program

Strip


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()+"--");
    }
}

Leave a Comment