String ccc=” he l l o , w o r l d “; 

System.err.println(“去左边空格:”+ccc.replaceAll(“^\\s*”, “”)+”————”); 

System.err.println(“去右边空格:”+ccc.replaceAll(“\\s*$”, “”)+”————”); 

System.err.println(“去所有空格:”+ccc.replaceAll(“\\s”, “”)+”————”); 

System.err.println(“去两端空格:”+ccc.replaceAll(“^\\s*(.*?)\\s*$”,”$1″)+”————”);