Java Recycling mechanism __utf-8

Source: Internet
Author: User

1 The following program which can implement GBK encoded byte stream to UTF-8 encoded stream: byte[] src, des; ()

A des=string.frombytes (src.) GBK "). GetByte (" UTF-8 ");
B des= New String (SRC, "GBK"). GetByte ("UTF-8");
C des= New String ("GBK", SRC). GetByte ();
D Des=string.encode (String.decode (src, "GBK"), "UTF-8");

Note: Steps for action:
* First decode in code:
* 1 decoding the string with new string (SRC, "GBK")
* 2 UTF-8 encoded byte Group with getBytes ("UTF-8")
2 The following code occurs once FULLGC, how many characters the above code retains in the heap space. ()
public class Test1 {

public static void Main (string[] args) {
    string string = ' 0123456789 ';
    String string2 = "0123456789";
    String string3 = string2.substring (5);//delete the first five characters.
    System.out.println (string3);//56789
    String String4 = new string (string3);
    System.out.println (String4.length ()); 5
    String string5 = new String (String3.tochararray ());
    System.out.println (String5.length ()); 5
}

}
A 5
B 10
C 15
D 20

Annotations: Java recycling mechanism:
* Garbage collection is mainly for the memory of the heap area recovery, because the stack area recovery is mainly with the thread release, heap area is divided into 3 areas:
* young Generation (younggeneration), the older generation (oldgeneration), Permanent generation (permanentgeneration)
* Young generation: When an object is created (new), it is usually placed in younger (in addition to the objects that occupy larger memory), and after the minor Gc (for the memory of the younger generation), the surviving objects are moved to the older generation.
* Older generation: The younger generation move over the object called the old generation, there are some memory-intensive objects, FULLGC mainly for the older generation of memory release.
* Permanent generation: Storage of final constants, static variables, constant pools
* String4 and STRING5 are directly new objects, and substring () its source code is also new object, because the string is intercepted from the constant pool, It's actually a new piece of memory, and then the captured string is saved.

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.