Home > Java > javaTutorial > body text

How to use intern()? Summary of intern() instance usage

伊谢尔伦
Release: 2017-06-11 09:36:40
Original
2753 people have browsed it

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 string and string-valued constant expressions 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

1. What is the concept of intern method in java

How to use intern()? Summary of intern() instance usage

Introduction: public String intern() returns the normalized representation of a 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 rules: for any two strings s and t, if and only if s.equals(t) is true, s.intern() == t.inter

2. Analysis of the role of intern() in Java

How to use intern()? Summary of intern() instance usage

##Introduction: Reading today When I was reading a book, I noticed the intern() method of String. I have never used it before. I have only seen this method but I have not looked at it carefully. So I took a look today. Personally, I think adding this method to the String class may be to improve performance a little bit, because fetching data from the constant pool is faster than fetching data from the heap. (Personal feeling)

3. Detailed explanation of intern() in String object

How to use intern()? Summary of intern() instance usage

Introduction: 1. First of all, String does not belong to the 8 basic data types. String is an object. Because the default value of an object is null, the default value of String is also null; but it is a special object that has some characteristics that other objects do not have. 2. new String() and new String("") both declare a new empty string, which is an empty string and not null;

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

How to use intern()? Summary of intern() instance usage

## Introduction: 1. String issues Strings are used in our usual coding work It is actually very practical and relatively simple to use, so few people have done particularly in-depth research on it. On the other hand, interviews or written tests often involve more in-depth and difficult questions. When recruiting, I occasionally ask candidates relevant questions. This does not mean that the answers must be particularly correct and in-depth. Usually, the purpose of asking these questions is two-fold. The first is to test the understanding of the basic knowledge of JAVA. The second is to test the basic knowledge of JAVA. The second is to examine the applicant's attitude towards technology.

5.

Summary of experience in using intern() method in JAVA

How to use intern()? Summary of intern() instance usage

Introduction: Generally we rarely use the intern method. Today I will explain what this method does and what it is used for

6 .

Detailed method analysis of the difference between ==, equals() and intern() in Java

How to use intern()? Summary of intern() instance usage

Introduction: This article mainly introduces the difference between the == operator and the equals method in Java and the relevant information on the detailed explanation of the intern method. Friends in need can refer to it

7. Java Example - String Optimization

How to use intern()? Summary of intern() instance usage

Introduction: The following example demonstrates the use of String .intern() method to optimize the string:

8. String intern method

How to use intern()? Summary of intern() instance usage

Introduction: String a = "ab"; String b = new String("ab"); System.out.println(a == b); System.out.println( a.equals(b)); System.out.println(b.intern() == a); System.out.print ...

[Related Q&A recommendations]:

Java String intern() method problem

Java: Determining string equality

Java's StringPool is stored in the method area, is it shared by all classes?

java - String intern problem

java - String Questions about intern method

The above is the detailed content of How to use intern()? Summary of intern() instance usage. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!