Thursday 19 June 2014

replace (char oldChar, char newChar)

public String replace(char oldChar, char newChar)
return a string derived from this string by replacing every occurrence of oldChar with newChar.

class StringReplace{
 public static void main(String args[]){
  String s1 = "aaaaa";
  String s2 = s1.replace('a', 'A');
  
  System.out.println("s1 = " + s1);
  System.out.println("s2 = " + s2);
 }
}

Output
s1 = aaaaa
s2 = AAAAA


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment