Replace Character In A String Example Java Program


Replace Character In A String Example Program

public class ReplaceCharacterInString{
   public static void main(String args[]){
      String str ="This is a Java Dutorial";
      System.out.println("The input string is:  "+str );
	  System.out.println("After replacement, the string is: ");
      System.out.println(str.replace('D', 'T'));
   }
}

Sample Output

Output is:
The input string is:  This is a Java Dutorial
After replacement, the string is:
This is a Java Tutorial