Java - Strings and String Handling
What will be the output of this code?
String s1 = "abc";
String s2 = s1.replace('a', 'z');
System.out.println(s1 + " " + s2);String s1 = "abc";
String s2 = s1.replace('a', 'z');
System.out.println(s1 + " " + s2);replace() method returns a new string with replacements; original string remains unchanged.s1 is "abc"; s2 is "zbc" after replacing 'a' with 'z'.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions