Java String.intern() method returns a canonical representation for the string object.
A pool of strings, initially empty, is maintained privately by the class String.
Java String intern() Method Example
public class InternExample {
public static void main(String[] args) {
String str = "javaguides";
String newStr = new String("javaguides");
System.out.println(newStr.intern().equals(str));
System.out.println(newStr.equals(str));
newStr.intern();
str.intern();
}
}
Output:
true true
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course