[Solved] How can use JAVA 8 filter for following code [closed]


Following snippet might be a point to start with.

URL url = new URL("http://example.com/acct/StatsClientListService"
        + "?clientType=AllClient&something=interesting");
Stream.of(url.getQuery().split("&"))
        .collect(Collectors.toMap(
                s -> s.replaceFirst("^(.*)=.*", "$1"), 
                s -> s.replaceFirst("^.*=(.*)", "$1")))
        .forEach((k, v) -> 
                System.out.printf("param: %s  value: %s%n", k, v)
        );

output

param: clientType  value: AllClient
param: something  value: interesting

edit If the URL string contain only the path and (optional) the query you might start with this snippet.

String urlString = "/acct/StatsClientListService"
        + "?clientType=AllClient&something=interesting";
if (urlString.contains("?")) {
    String query = urlString.substring(urlString.indexOf("?") + 1);
    Stream.of(query.split("&"))
        .collect(Collectors.toMap(
                s -> s.replaceFirst("^(.*)=.*", "$1"),
                s -> s.replaceFirst("^.*=(.*)", "$1")))
        .forEach((k, v)
                -> System.out.printf("param: %s  value: %s%n", k, v)
        );
}

output

param: clientType  value: AllClient
param: something  value: interesting

note Additional checks for the urlString are necessary. Depending on which values are possible.

6

solved How can use JAVA 8 filter for following code [closed]