Array set algorithm of Set frame

Source: Internet
Author: User
Tags array length


How to test the health of the program?

If you want to know the CPU and memory of the program running, you can use the aircraft, so you can know the stability of the program. The aircraft can be found in the bin directory of the JDK. such as: 650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250015.jpg "alt=" image "Style=" Border-style: None;background-color:rgb (255,255,255); "/>

Array Collection algorithm:

1. Arrays and sets of differences and relations: arrays are limited storage (which specifies that the array length can only store so many values), and the collection is infinite storage, but in fact the collection is made of arrays.

2. The principle of the array set algorithm: When storing a value in the collection, the collection will request an appropriate length of the array to store, the second time the value is stored, if the length of the array is not enough to store the second value, re-request a longer array, the original array of contents into the first, And then store the new content in. There is no need to worry that the original array will waste memory because the system's garbage collection mechanism is automatically recycled. For example, when storing an A in an array, request an array of length 1 to store, and when you store a B in it, because the array length is not enough, it will re-apply for an array of length 2, first import the original A, and then store the B in. The original array is recycled because it is not referenced. such as:  650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250016.jpg "alt=" image "style=" Border-style:none;background-color:rgb (255,255,255);/>3. Code implementation: 3.1 The first version of the 3.1.1 code is as follows:  650) this.width=650; " Src= "http://os78f4hny.bkt.clouddn.com/201707250017.jpg" alt= "image" Style= "Border-style:none;background-color: RGB (255,255,255); "/>650" this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250018.jpg "alt=" image " Style= "Border-style:none;background-color:rgb (255,255,255);/>3.1.2 Debug as follows:  650) this.width=650;" Src= "http ://os78f4hny.bkt.clouddn.com/201707250019.jpg "alt=" image "Style=" Border-style:none;background-color:rgb ( 255,255,255); "/> Breakpoint can let the program run here to stay, debugging (right-click Debug mode is Debugging) can make it step-by-step execution, you can see the detailed results of each step. as follows: &NBsp;650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250020.jpg "alt=" image "Style=" Border-style: None;background-color:rgb (255,255,255); "/>650) this.width=650; src=" http://os78f4hny.bkt.clouddn.com/ 201707250021.jpg "alt=" image "Style=" Border-style:none;background-color:rgb (255,255,255);  650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250022.jpg "alt=" image "style=" Border-style:none;background-color:rgb (255,255,255); "/>

3.2 Second version: Copying values in a loop is slower, and there is a system.arraycopy method that can be copied directly to memory, which is implemented by other languages that can manipulate memory directly (such as C). The 3.2.1 code is as follows:  650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250023.jpg "alt=" image "style=" Border-style:none;background-color:rgb (255,255,255); "/>3.2.2 aircraft test results are as follows:  650) this.width=650;" Src= "http ://os78f4hny.bkt.clouddn.com/201707250024.jpg "alt=" image "Style=" Border-style:none;background-color:rgb ( 255,255,255); "/>3.3 third version: The first two to re-request the array each time the value is stored, so that the run time, in order to reduce the running time can be in each request to the array to make the length of the new array is a multiple of the length of the old array, although it will waste some memory, However, a small amount of memory can be wasted for faster running time. The 3.3.1 code is as follows:  650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250025.jpg "alt=" image "style=" Border-style:none;background-color:rgb (255,255,255); "/>3.3.2 aircraft test results are as follows:  650) this.width=650;" Src= "http:/ /os78f4hny.bkt.clouddn.com/201707250026.jpg "alt=" image "Style=" Border-style:none;background-color:rgb ( 255,255,255); "/>3.4 system written version:  650) this.width=650;" Src= "http://os78f4hny.bkt.clouddn.com/201707250027.jpg" alt= "Image" styLe= "Border-style:none;background-color:rgb (255,255,255);"/>650) this.width=650; "src=" http:/ Os78f4hny.bkt.clouddn.com/201707250028.jpg "alt=" image "Style=" Border-style:none;background-color:rgb ( 255,255,255); "/>3.5 Standard Version:  650) this.width=650;" src= "Http://os78f4hny.bkt.clouddn.com/201707250029.jpg" alt = "image" Style= "Border-style:none;background-color:rgb (255,255,255);"/>

650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250030.jpg "alt=" image "style=" Border-style:none ; Background-color:rgb (255,255,255); "/>

650) this.width=650; "src=" http://os78f4hny.bkt.clouddn.com/201707250031.jpg "alt=" image "style=" Border-style:none ; Background-color:rgb (255,255,255); "/>


Array set algorithm of Set frame

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.