How to replace characters in a string using java?
In the following example, we use the replace method of the java String class to replace characters in the string:
public class StringReplaceEmp{ public static void main(String args[]){ String str="Hello World"; System.out.println( str.replace( 'H','W' ) ); System.out.println( str.replaceFirst("He", "Wa") ); System.out.println( str.replaceAll("He", "Ha") ); }}
The output result of the above code example is:
Wello World Wallo World Hallo World
The above is the Java example - Contents of string replacement, please pay attention to the PHP Chinese website (www.php.cn) for more related content!