Here you can find the source of concatenateURL(URL url, String query)
public static URL concatenateURL(URL url, String query)
//package com.java2s; //License from project: Open Source License import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL concatenateURL(URL url, String query) { try {//ww w .jav a 2 s.com return url.getQuery() != null && url.getQuery().length() > 0 ? new URL(url.getProtocol(), url.getHost(), url.getFile() + "&" + query) : new URL(url.getProtocol(), url.getHost(), url.getFile() + "?" + query); } catch (MalformedURLException e) { throw new IllegalArgumentException("Concatenated URL was malformed: " + url.toString() + ", " + query); } } }