Saturday 21 June 2014

replace (CharSequence target, CharSequence replacement)

public String replace(CharSequence target, CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

class StringReplaceStr{
 public static void main(String args[]){
  String s1 = "Hi How Are you. How is Job";
  String s2 = s1.replace("How", "Where");
  
  System.out.println("s1 = " + s1);
  System.out.println("s2 = " + s2);
 }
}

Output
s1 = Hi How Are you. How is Job
s2 = Hi Where Are you. Where is Job





Prevoius                                                 Next                                                 Home

No comments:

Post a Comment