Just curious to know that in terms of performance if we want to replace some characters in out string which may or may not be present in the input string should we check for the existence of the char sequence in the String using index of>0 or we can directly call the String replace function.
Thanks, Vaibhav
The cost of the check is built into the cost of the replace, so just use the replace directly with checking first.
Also, it is an optimization, so you shouldn't be even thinking of coding like that unless you can prove there's a significant performance problem at that line of code. The compiler, JDK and JVM are pretty smart - smart enough for you not to have to worry about this kind of thing.