String is one of the most widely used Java Class. Here I am listing some important Java String Interview Questions and Answers. This will be very helpful to get complete knowledge of String and tackle any questions asked related to String in interview. What is String in Java? String is a data type? String is a Class in java and defined in java.lang package. It’s not a primitive data type like int and long. String class represents character Strings. String is used in almost all the Java applications and there are some interesting facts we should know about String.
Read full article from Java String Interview Questions and Answers
What does String intern() method do?
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.
This method always return a String that has the same contents as this string, but is guaranteed to be from a pool of unique strings.
This method always return a String that has the same contents as this string, but is guaranteed to be from a pool of unique strings.
Why String is popular HashMap key in Java?
Since String is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for key in a Map and it’s processing is fast than other HashMap key objects.Read full article from Java String Interview Questions and Answers