I was just working on one of my java code in which I am using Java String.replace method. So while testing the replace method as in one situation I am planning to put junk v
Take a look at this example:
"" + "abc" + ""
What is result of this code?
Answer: it is still "abc". So as you see we can say that all strings have some empty strings before and after it.
Same rule applies in-between characters like
"a"+""+"b"+""+"c"
will still create "abc"
So empty strings also exists between characters.
In your code
"val".replace("","p")
all these empty strings ware replaced with p which result in pvpaplp.
In case of ""+""+..+""+"" assume that Java is smart enough to see it as one "".