What is different between replace, replaceAll and replaceFirst in String java example
Java code example for different between replace, replaceAll and replaceFirst in String.
public class Test {
public static void main(String[] args) {
String st = new String("Test String Here");
String st1 = new String("test string test here");
String st2 = st.replace("Test", "New");
System.out.println(st2);
st2 = st1.replaceAll("test", "New");
System.out.println(st2);
st2 = st1.replaceFirst("test", "New");
System.out.println(st2);
}
}
public class Test {
public static void main(String[] args) {
String st = new String("Test String Here");
String st1 = new String("test string test here");
String st2 = st.replace("Test", "New");
System.out.println(st2);
st2 = st1.replaceAll("test", "New");
System.out.println(st2);
st2 = st1.replaceFirst("test", "New");
System.out.println(st2);
}
}
Comments
Post a Comment