Found a total of 2 related content
How to use the intern method in Java String
Article Introduction:Introduction to the constant pool There are 8 basic types and a special type String in the JAVA language. In order to make them run faster and save more memory, these types provide a concept of a constant pool (in the method area). The constant pool is similar to a cache provided by the JAVA system level. The eight basic types of constant pools are all coordinated by the system, and the String type constant pool is special. There are two main ways to use String's constant pool: String objects declared directly using double quotes will be directly stored in the constant pool. If the String object is not declared with double quotes, you can use the intern method provided by String to put it into the constant pool. Introduction to intern method
2023-05-05
comment 0
850
What is the purpose of String intern() method in Java?
Article Introduction:String is a class in Java that stores character sequences and it belongs to the java.lang package. Once String objects are created, they cannot be modified (immutable). All String objects are stored in a separate memory location in the heap area, called the String constant pool. Whenever a string value is defined, the JVM creates a string object with the given value in the string constant pool. So if you run the above program, two string values will be created in the string constant pool. intern() method This method returns the value of the current string from a pool of unique string values. Whenever you call this method on a specific String, if the String constant pool already contains a String equal to it
2023-09-20
comment 0
596