Possible Duplicate:
When to use intern()
When should we use intern method of String?
Does java intern strings automatically ? If it does why does string have an explicit intern method ? Any particular use cases when an explicit call is needed ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java does not intern strings created at run-time automatically. (It does do so for string constants at compilation time).
I had a specific use case where I saved ~30% of heap used in a component that was receiving records expressed in a map. The set of keys in each record were identical, yet every new record received created a new instances of the key strings. By interning the key strings, heap consumption was greatly reduced.