1

I have following URL: https://play.google.com/store/apps/details?id=eu.bandainamcoent.verylittlenightmares&hl=en";

I want to extract this value: eu.bandainamcoent.verylittlenightmares

URI uri = new URI(URL);
uri.getQuery();

I'll get this: id=eu.bandainamcoent.verylittlenightmares&hl=en

How to cut id= and &hl=en? And &hl=en may not exist and can be different, like &hl=de etc.

0

1 Answer 1

2

There are no function in URI to do this, but here is a trick to solve it:

Map<String, String> params = Arrays.stream(uri.getQuery().split("&"))
        .map(s -> s.split("="))
        .collect(Collectors.toMap(k -> k[0], v -> v.length > 1 ? v[1] : ""));
String id = params.get("id"); // eu.bandainamcoent.verylittlenightmares
String hl = params.get("hl"); // en

We are sure that the only separator between two parameters is &, and the parameter have a name and value separated by =, for that you split with &, and for each result split with =, and the result is a Map which contain the param name as key and value as value.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.