Thanks Campbell for your reply.
The idea came from a test question in OCA Java® SE 8 Programmer I Exam Guide by Kathy Sierra Bert Bates. specifically, question 9 of chapter 6 self test.
I don't know if it is OK to include the full question here but the statement
s = " " + i;
was inside a for loop where s is created by concatenating " " with the int variable i.
And the question was to estimate how many objects will exist in memory after the loop is done assuming the garbage collector dose NOT run.
The provided answer state that " " is created once and reused in every loop iteration.
The resulting String (s) of the concatenating will be an object created on every loop iteration.
My question is about the int i that is concatenating with " ".
will this variable be converted to a string and then concatenated with s.
If this the case what about that converted string i, does is it live in memory until the loop is done. If this is the case, the number of objects created will be double the provided answer.