I need to encode a String to byte array using UTF-8 encoding. I am using Google guava, it has Charsets class already define Charset instance for UTF-8 encoding. I have 2 way
If you already have the Charset, then use the 2nd version as it's less error prone.