InterviewSolution
| 1. |
What Is Intern() Method In String? |
|
Answer» Using intern() method you can still get string OBJECT from the POOL (if it exists) even if NEW operator is used to CREATE a string. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is ADDED to the pool and a reference to this String object is returned. Using intern() method you can still get string object from the pool (if it exists) even if new operator is used to create a string. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned. |
|