http://www.yahoo.com &b=128&f=norefer
I want to remove &b=128&f=norefer
String finalUrl =decodedUrl.repl
you should be using URL object of java for this :
http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html#getHost()
[search for getHost() method in it.]
You can use the following regex replacement to remove everything after the first ampersand:
"http://www.yahoo.com &b=128&f=norefer".replaceAll("&.*$", "");
Is the reason for not wanting a hardcoded string that you wish to be able to remove some other string as well? Then you could consider writing a method like:
public String removeNoise(String url, String noisePattern) {
return url.replace(noisePattern, "");
}