Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 4
    @mcherm: Even if the performance difference is small, I prefer using objects (Charset, URL, etc) over their string forms when possible. Commented Dec 7, 2010 at 9:08
  • 7
    Note: "Since 1.6" public String(byte[] bytes, Charset charset) Commented Jan 20, 2012 at 15:49
  • 1
    Regarding "avoids performing the Charset lookup for every conversion"... please cite some source. Isn't java.nio.charset.Charset built on top of String.getBytes and therefore has more overhead than String.getBytes? Commented Jul 14, 2012 at 22:43
  • 2
    The docs do state: "The behavior of this method when this string cannot be encoded in the given charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required." Commented Oct 19, 2013 at 20:30
  • 28
    Note: since Java 1.7, you can use StandardCharsets.UTF_8 for a constant way of accessing the UTF-8 charset. Commented Jul 29, 2014 at 23:27