« Back
package com.string; public class StrinReplace { public static void main(String[] args) { String str = "Hello Codersarts"; str =str.replace('e','o'); System.out.println("After replacing e with o :"); System.out.println(str); String str1 = "Hello Codersarts , Hello Ankit"; str1 =str1.replace("Hello","Hi"); System.out.println("After replacing Hello with Hi :"); System.out.println(str1); String str2 = "Hi Codersarts , Hi Ankit"; str2 =str2.replace("Hi","Hello"); System.out.println("After replacing Hi with Hello :"); System.out.println(str2); } }
After replacing e with o :
Hollo Codorsarts
After replacing Hello with Hi :
Hi Codersarts , Hi Ankit
After replacing Hi with Hello :
Hello Codersarts , Hello Ankit
×
Report a Problem:
Description:
Submit