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.