Sunday, January 26, 2014

Example of String.trim()

String.trim() returns a copy of the string, with leading and trailing whitespace omitted.

package javaextrimstring;

public class JavaExTrimString {

    public static void main(String[] args) {
        doTrim("abc def");
        doTrim(" abc def ");
        doTrim("   abc def");
        doTrim(" _ abc def");
    }
    
    static private void doTrim(String s){
        System.out.println(s + " => " + s.trim());
    }
}

Example of String.trim()
Example of String.trim()

No comments:

Post a Comment