Hi to all Anybody let me know about appendReplacement & replaceAll methods.I am unable to understand the difference between them.I have also read from sun documentation but unable to understand.Please any one explain me both with suitable examples.Are they present in the syallabus of scjp 5.
SCJP 5.0(75%), SCWCD 5.0(88%)
pradeep singh
Ranch Hand
Joined: Oct 23, 2007
Posts: 338
posted
0
Please tell me above given.
Remko Strating
Ranch Hand
Joined: Dec 28, 2006
Posts: 893
posted
0
I don't know what you exactly mean, but maybe the api of the String replaceAll could help.
The find(), appendReplacement(), and appendTail() methods are supposed to be used together to find a match based on a regular expression, and then replace it with a replacement string. The replacement string is calculated with Java code.
Although, this is incredibly powerful, it is also a little awkward to use (for people that want to use regular expressions replacement strings instead of using Java to calculate the replacement string).
The replaceFirst() and replaceAll() methods allows the user to simply specify a regular expression and the regex replacement string -- as parameters. This makes it much simpler to use, and not as flexible. Also, these two methods are actually convenience methods, as they are build upon the find(), and appendXXX() methods.