Skip to main content

replace() method in Java.(three types of use replace() method in JAVA.replace(),replaceFirst(),replacrAll())

CODING:
class replace
{
   public static void main(String args[])
    {
      String S = new String("ProgrXmming ExXmples of Core & Core JXVX");
      System.out.println("Name                             :" + S);
      System.out.println("After replacing all X with a     :" + S.replace('X', 'a'));
      System.out.println("After replacing Core with Advance:" + S.replaceFirst("Core", "Advance"));
      System.out.println("After replace All                :" + S.replaceAll("(.*)of Core & Core JXVX", "hi Alien Kartik."));
     //here not define "of Core & Core JXVX",output is display two time,because before memory size of string greater than after string.
    }
}

Comments