<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.2</version>
</dependency>
public class TestParseURL {
public static void main(String[] args) throws MalformedURLException, URISyntaxException {
String url="https://devslackbot.zoomdev.us?code=JUUNNgkokS_moZK29PtQxCP0mbcj2adiA&state=38977182-15b7-42f3-b855-453b3312122e";
Map<String, String> map = parseURLParamsToMap(url);
for(Map.Entry<String,String> item: map.entrySet()){
System.out.println(item.getKey()+":"+item.getValue());
}
}
public static Map<String,String> parseURLParamsToMap(String urlString) throws MalformedURLException, URISyntaxException {
Map<String,String> map=new HashMap<>();
URL url=new URL(urlString);
List<NameValuePair> paramsPair = URLEncodedUtils.parse(url.toURI(), "utf-8");
for(NameValuePair item:paramsPair){
map.put(item.getName(),item.getValue());
}
return map;
}
}