Java Reference
In-Depth Information
There is also a single-argument form of copyValueOf that copies the en-
tire array. For completeness, two static valueOf methods are also equi-
valent to the two String constructors.
The toCharArray method is simple and sufficient for most needs. When
you need more control over copying pieces of a string into a character
array, you can use the getChars method:
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBe-
gin)
Copies characters from this String into the specified array.
The characters of the specified substring are copied into the
character array, starting at dst[dstBegin] . The specified sub-
string is the part of the string starting at srcBegin , up to but
not including srcEnd .
13.2.7. Strings and byte Arrays
Strings represent characters encoded as char values with the UTF -16 en-
coding format. To convert those char values into raw byte values re-
quires that another encoding format be used. Similarly, to convert indi-
vidual "characters" or arrays of raw 8-bit "characters" into char values
requires that the encoding format of the raw bytes is known. For ex-
ample, you would convert an array of ASCII or Latin-1 bytes to Unicode
characters simply by setting the high bits to zero, but that would not
work for other 8-bit character set encodings such as those for Hebrew.
Different character sets are discussed shortly. In the following con-
structors and methods, you can name a character set encoding or use
the user's or platform's default encoding:
public String(byte[] bytes, int start, int count)
 
Search WWH ::




Custom Search