Here you can find the source of encode(String value, Charset charset)
public static String encode(String value, Charset charset)
//package com.java2s; //License from project: Apache License import static java.nio.charset.StandardCharsets.*; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.Charset; public class Main { /** Uses URLEncoder to translate a string into application/x-www-form-urlencoded format, using the given Charset. */ public static String encode(String value, Charset charset) { try {/*from w w w . j av a2 s . c om*/ return URLEncoder.encode(value, charset.name()); } catch (UnsupportedEncodingException ex) { throw new IllegalArgumentException("Characterset is not supported."); } } /** Uses URLEncoder to translate a string into application/x-www-form-urlencoded format, using UTF-8 as Charset. */ public static String encode(String value) { return encode(value, UTF_8); } }