Replace
1. replace(): This method is used to replace all the occurrences of a single character with some another character, within the string.
The general form is.
String replace(char ch1,char ch2)
Where:
ch1 is used to specify the character which we want to replace .
ch2 is used to specify the character by which we want to replace the ch1
E.g.
String s="hello";
String s2;
s2=s.replace('l','t');
System.out.println(s2);
Output:
hetto
2. toString(): This method is call when we convert any value to type String . If we want to
System.out.println(ob);
Where ob is an object of the Sample class, it will generate an error, as we have not defined the toString() method for the class Sample
Comments
Post a Comment