Infolinks In Text Ads

Jul 12, 2010

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);
           
        }
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...