public class Test{ public static void main(String[] args) { String str = " 这里是Java优才,到Java优才学习 Java"; String regStr = "Java"; str = str.replaceAll(regStr, "ABC"); System.out.println("str="+str); } }//源代码片段来自云代码http://yuncode.net