Shaanxi Diesel Engine-mechanical IP -------- QQ request huichuang

Source: Internet
Author: User

We found that string. the string returned by substring () will still save the original string. In fact, the string generated in substring is a great design to share the content array with the original string, this prevents the substring from re-copying the character array each time. This design can save a lot of memory in many cases, because these strings all reuse the original string, and only identify each string through the start and end values of the int type. In the above case, a small number of strings are intercepted from a huge string for future use. Such a design results in a large amount of redundant data.

Since the root cause of a large amount of memory usage is that string. substring () contains a large number of original strings in the returned results, an obvious way to reduce memory waste is to remove these original strings. There are many methods. Here we adopt a more intuitive method, that is, call New String again to construct a string that only contains the captured string.

String newString = new String(largeString.substring(0,2));
  • 1
Java 7 Implementation

In Java 7, the implementation of substring discards the sharing mechanism of the character array of the previous content. For the sub-string (except itself), array replication is used to realize that a single string holds its own content.

--------------------- This article is from the csdn blog of the wheat field. For the full-text address, click: 77647800? Utm_source = copy

Shaanxi Diesel Engine-mechanical IP -------- QQ request huichuang

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.