Agreed with @BalusC.
I would also like to point out that what you are trying to do is not really "encoding" in the normal sense of the phrase "URL encoding". Encoding implies that that there is a reverse decoding step that will give you the original URL back. Unless you have some business rule that precludes "-" characters (e.g. hyphens if you are creating URL names from "text"), your transformation will not be reversible.
What you appear to be doing is transforming URL strings into other URL strings according to some rule that probably not reversible. It is not at all surprising that the URLEncoder class (which implements a particular standardised reversible encoding) is not implementing your (application specific) transformation.
As @BalusC points out, the correct approach is to transform the URL strings (according to your application's needs) before you encode them. Indeed, it may be better (e.g. safer) to implement the transformation on the URL string's components ... before you assemble the complete URL.
(And I am taking for granted that the URLs are being used in a context that actually require the encoding implemented by URLEncoder.)