The difference Between String.replace() and String.replaceAll()

  • amethlex
  • 12 Nov 2016
  •   Comments Off on The difference Between String.replace() and String.replaceAll()
work-in-chuang-bian-de-xiao-dou-dou-1-mask9

摘自java8 doc:

String replace(char oldChar, char newChar) Returns a string resulting from replacing all occurrences of oldChar in this string with newChar.

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.

String replaceFirst(String regex, String replacement) Replaces the first substring of this string that matches the given regular expression with the given replacement.

*关于regex:请参考另一篇文章 Regex Summary of Java

689total visits,5visits today