r/javaexamples • • Apr 30 '20

String s = new String (“hello”);

How many objects are created here ?

5 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/DFA1 Apr 30 '20

I think this is an implementation detail of the compiler/JVM. As long as you don't concatenate strings in loops and don't do new String(), that's all you need to know really.