Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




String - replace() Method


String replace(char oldCharacter, char newCharacter)


replace(..) method is used to replace an existing character with a new character.


Example :



public class Test{
	public static void main(String[] arg){
		String firstString = "Hello"; 
		String newString=firstString.replace('l','g');	   
		
		System.out.println("The new String is : "+newString);
	}
}


Output :



  The new String is : Heggo

It replaces all ls with g.