String s1 = new String(“abc”); How many string objects will this code create?
•
Java
String s1 = new String("abc"); How many string objects will this code create?
The answer is to create one or two
Create an object: the string ABC already exists in the string constant pool, so you don't need to create it here. You can directly create an object in the heap
Create two cases: if the string ABC does not exist in the string constant pool, you need to create objects in both the string constant pool and the heap
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码