private String unmangleQueryString(String urlToFilter) {
        int firstAmp = urlToFilter.indexOf('&');
        if (firstAmp > 0) {
            int firstQuestionMark = urlToFilter.indexOf('?');
            if (firstQuestionMark == -1) {
                return urlToFilter.replaceFirst("&", "?");
            }
        }
        return urlToFilter;
    }
private String unmangleQueryString(String urlToFilter) {
        int firstAmp = urlToFilter.indexOf('&');
        if (firstAmp > 0) {
            int firstQuestionMark = urlToFilter.indexOf('?');
            if (firstQuestionMark == -1) {
                return urlToFilter.replaceFirst("&", "?");
            }
        }
        return urlToFilter;
    }
private String unmangleQueryString ( String urlToFilter ) { int firstAmp = urlToFilter . indexOf ( ' ' ) ; if ( firstAmp > 0 ) { int firstQuestionMark = urlToFilter . indexOf ( ' ' ) ; if ( firstQuestionMark == - 1 ) { return urlToFilter . replaceFirst ( "&" , "?" ) ; } } return urlToFilter ; }
A common error to find is a query string that starts with an & instead of
a ? This will fix that error. So http://foo.com&a=b will be changed to
http://foo.com?a=b.

@param urlToFilter
@return corrected url
A common error to find is a query string that starts with an & instead of a ? This will fix that error . So http : // foo . com&a = b will be changed to http : // foo . com?a = b .