Java String - Replacement

by Dan Bunker - Dec. 14, 2017

 

Java String Replace Methods

 

Changing the content of a String is something that is often needed when working with Strings. The String class provides four methods that can help you replace content. They are:

  • replace - single character
  • replace - multiple characters
  • replaceFirst - replace first match
  • replaceAll - replace all matches

The replaceFirst and replaceAll methods utilize regular expressions. This lesson won't cover regular expressions. The more you know about those, the more you can accomplish any kind of String replacement needed.