Java Performance optimization

Source: Internet
Author: User

1.String is more memory space than stringbuffer, when stitching strings

Cause: String The actual amount of memory consumed by this object does not correspond to its own number of bytes.

Conclusion: It should be used less string, especially the string "+ =" operation, not only the original string object
It is not possible to continue to use, but it also produces multiple new objects, which makes it a higher memory footprint.

2. Two-dimensional arrays occupy more memory space than one-dimensional arrays

Cause: For a two-dimensional array, it takes up much more memory space than
It opens up the number of array elements.

3. Increase memory query speed (hash table) with HashMap

4. Increase the speed of array interception with "arrayCopy ()"

Example: System.arraycopy (oldarray,100,newarray,0,120);

Copies an array from the specified source array, starting at the specified location and ending at the specified position in the destination array.

Java Performance optimization

Related Article

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.