Mastering Java: The Ultimate 2025 All-In-One Quiz to Excel in 'Thinking in Java

Question: 1 / 510

What purpose does the method intern() in String class serve?

Converts the string to integer

Internally sorts the string

Ensures unique string references

The method intern() in String class serves the purpose of ensuring unique string references. Option A is incorrect because this method does not convert strings to integers. Option B is incorrect because it does not involve any sorting of strings. Option D is incorrect because it does not pertain to the purpose of the intern() method. The intern() method mainly helps to optimize memory usage by returning a string reference from the string pool if the same string already exists in the pool, instead of creating a new string object. This helps to avoid creating multiple string objects with the same value, thus saving memory. Therefore, the correct answer is C.

Get further explanation with Examzify DeepDiveBeta

Optimizes memory usage for strings

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy