How to Replace content from a Given String

How to Replace content from a Given String
SOURCE : ReplacingDATA.java

import java.util.StringTokenizer;

public class ReplacingDATA {

public static void main(String[] args) {

String S = " I Love You";
StringTokenizer st = new StringTokenizer(S);
StringBuilder sb = new StringBuilder();

while (st.hasMoreTokens()) {

String Current = st.nextToken();
if (Current.equalsIgnoreCase("Love")) {

Current = "Hate";
}
sb.append(Current + " ");

}

System.out.println(sb);
}

}


INPUT

String S = " I Love You";
String replace= "Hate"



OUTPUT

I Hate You






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment