manoj kumar jena wrote:System.out.println("12.0".replaceAll(".0",""));
The above line prints 12 but the following line prints a blank string, why? it should print 10.
:!:
System.out.println("10.0".replaceAll(".0",""));
replaceAll(regex,replacementString); this function uses regular expression for matching.
For ".0" : dot means any character in regular expression, 0 means 0, so regex engine will try to find anycharacter ending with 0.
In first try it will find 10--------> 1 character ending with 0
in Second try it will find .0------> . character ending with 0.