replace
和有什么区别和replaceAll
字符串的方法?
在以下示例中,代码给出 same
输出。在这两种情况下all
字符串的实例被替换。
String first = "Here is a cat There is a cat";
first = first.replace("cat", "dog");
System.out.println(first);
输出:
Here is a dog There is a dog
String second = "Here is a cat There is a cat";
second = second.replaceAll("cat", "dog");
System.out.println(second);
输出:
Here is a dog There is a dog
最佳答案
String replace(CharSequence target, CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
String replaceAll(String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
来源:http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
关于java - 替换和替换全部的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24731506/