This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Values of the String class or char type are represented in Unicode using 16-bit values. Are you asking how to determine the values of strings stored in other places, like files?
Joined: Apr 06, 2002
you Know that Constructor : String(byte bytes, String charsetName) Constructs a new String by decoding the specified array of bytes using the specified charset. I want to know how can I get charsetName of String.
Joined: Feb 22, 2001
To get a list of encodings supported by a particular release of the Java runtime, see the Supported Encodings document for that release. For example, for Java 1.3, see http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html This will give you a list of the possible charasetName values for the constructor. (Be sure to look at the link to the java.lang package document.) To determine which one to use, you need to know which one was used to represent the characters as the byte array you want to process. For example, if you are working on a Windows machine in the US, and the characters came from a file encoded as one character per byte, your data is probably encoded as Cp1252. If you are on a Unix machine in the US, it is more likely to be ISO8859_1 (a subset of Cp1252, unless the Java translation tables do something unusual with characters 0x80-0x9F). If you are on a Windows NT machine and data was read from a Unicode file, then the encoding would be UTF-16 if, as I recall, Windows uses a byte order mark for Unicode files.