Where is the Java constant pool stored

Source: Internet
Author: User

Run the following methods:

public class Test {
public static void Main (string[] args) {
String str = "ABC";
Char[] Array = {' A ', ' B ', ' C '};
String str2 = new string (array);
Use Intern () to put str2 string contents into a constant pool
STR2 = Str2.intern ();
This comparison is used to illustrate the string literal constants and we use intern to process the string after it is in the same place
System.out.println (str = = STR2);
Well, then, let's intern the hell out of here.
arraylist<string> list = new arraylist<string> ();
for (int i = 0; i < 50000000; i++) {
String temp = string.valueof (i). Intern ();
List.add (temp);
}
}
}

Results:



At Test.main (test.java:16)


The exception information tells us that PermGen is full. Oh, I know where the string constant pool is. PermGen is the so-called method area in the JVM specification.

The above excerpt from
Small example: How to explain the position of a string constant pool thanks to the original author!!!

Where is the Java constant pool stored

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.