How to Replace content from a Given String
SOURCE : ReplacingDATA.javaimport 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); }}INPUTString S = " I Love You";String replace= "Hate"OUTPUT
I Hate You

0 comments :
Post a Comment