Skip to main content
added 2 characters in body
Source Link

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied "12\0" => HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied "123\0" => HEX(31 32 33 00)

The official document not mentioned those above, and itit's not reasonable for the modern function design.

Misunderstanding in that and waste our life so much.

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied "12\0" => HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied "123\0" => HEX(31 32 33 00)

The official document not mentioned those above, and it not reasonable for the modern function design.

Misunderstanding in that and waste our life so much.

Using String.getBytes(buffer, len) to get bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied "12\0" => HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied "123\0" => HEX(31 32 33 00)

The official document not mentioned those above, and it's not reasonable for the modern function design.

Misunderstanding in that and waste our life so much.

added 151 characters in body
Source Link

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length(); + 1;// lenth() is 3
s.getBytes(buffer, count);   // 3copied +"12\0" 1=> =HEX(31 432 00)
s.getBytes(buffer, count + 1);   // it will copy 3copied bytes"123\0" only=> evenHEX(31 count32 =33 4.00)

The official document not mentioned those above, and it not reasonable for the modern function design. Waste

Misunderstanding in that and waste our life so much.

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length() + 1;  // 3 + 1 = 4
s.getBytes(buffer, count);   // it will copy 3 bytes only even count = 4.

The official document not mentioned those above. Waste our life so much.

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied "12\0" => HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied "123\0" => HEX(31 32 33 00)

The official document not mentioned those above, and it not reasonable for the modern function design.

Misunderstanding in that and waste our life so much.

Source Link

Using String.getBytes(buffer, len) to get char bytes.

"len" is the length to copy, but usually need to add 1 for the end of string '\0'.

For example:

String s = "123";
int count = s.length() + 1;  // 3 + 1 = 4
s.getBytes(buffer, count);   // it will copy 3 bytes only even count = 4.

The official document not mentioned those above. Waste our life so much.