Home  >  Article  >  Java  >  What is the concept of intern method in java

What is the concept of intern method in java

Y2J
Y2JOriginal
2017-05-19 09:41:523887browse

public String intern() returns the normalized representation of the string object. An initially empty string pool maintained privately by class String. When the intern method is called, if the pool already contains a string equal to this String object (determined using the equals(Object) method), the string in the pool is returned. Otherwise, adds this String object to the pool and returns a reference to this String object. It follows the following rule: for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true. All literal strings and string assignments constantsexpressions operate using the intern method. String literals are defined in §3.10.5 of the Java Language Specification. Returns: a string with the same contents as this string, but must be taken from a pool with unique strings.

[Related recommendations]

1.Java free video tutorial

2.Analysis of intern() in Java Function

3. Detailed explanation of intern() in String object

4. In-depth analysis of intern() method in Java

5. Summary of experience in using intern() method in JAVA

The above is the detailed content of What is the concept of intern method in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn