Java示例删除空格


Java示例删除空格

import java.util.regex.Matcher;

import java.util.regex.Pattern;



public class Main {

   public static void main(String[] argv) {

      String str = "This is a Java program. This is another Java Program.";

      String pattern="[\\s]";

      String replace = "";

      Pattern p = Pattern.compile(pattern);

      Matcher m = p.matcher(str);

      str = m.replaceAll(replace);

      System.out.println(str);  

   }

}