The Google Guava library (which I'd highly recommend anyway, if you're doing work in Java) has a Charsets
class with static fields like Charsets.UTF_8
, Charsets.UTF_16
, etc.
Since Java 7 you should just use java.nio.charset.StandardCharsets
instead for comparable constants.
Note that these constants aren't strings, they're actual Charset
instances. All standard APIs that take a charset name also have an overload that take a Charset
object which you should use instead.