This content has been marked as final. Show 2 replies
Inside the println, you are printing the result of the replace.
Outside the println, you are calculating the replace, discarding the result which is returned and printing the original value.
What you may have indended was
This question doesn't have anything to do with IO. Perhaps the "New to Java" forum is a better place next time. ;)
String z = "12345"; z = z.replace("5", "6"); System.out.println(z); //o/p is "12346".
821046 wrote:None. z.replace() behaves exactly the same way in both cases, but your code is only looking at the result in one of the cases.
what is the difference between putting z.replace("5","6") outside println and inside println ?