programming-examples/java/Basics/How to replace a substring inside a string by another one.java

8 lines
299 B
Java
Raw Normal View History

2019-11-18 14:44:36 +01:00
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") );
}
}