I have found various posts where escaping in Java is done with java.net.URLEncoder.encode.
However I have found in docs for URL that:
The
URLEncoderandURLDecoderclasses can also be used, but only for HTML form encoding, which is not the same as the encoding scheme defined in RFC2396.
Can someone explain me this situation?
The document correctly advises to use the URI class. The reason URLEncoder is still mentioned is I guess historical cause URLEncoder has been there since 1.0 while URI was added in 1.4.