Last active
August 29, 2015 14:18
-
-
Save leifoolsen/3f29e42d1451d8e97165 to your computer and use it in GitHub Desktop.
Guava Splitter: Compare strings and remove identical part of string. Split query string into a name-value Map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String s1 = http://localhost:8080/api; | |
String s2 = http://localhost:8080/api/books/search/any?offset=5&limit=5; | |
// Remove identical part from s2 | |
List<String> l = Lists.newArrayList(Splitter.on(s1).omitEmptyStrings().trimResults().split(s2)); | |
String s3 = l.get(0); // => /books/search/any?offset=5&limit=5 | |
// Split query string into name value | |
URI uri = URI.create(s3); | |
Map<String, String> split = Splitter.on('&').withKeyValueSeparator('=').split(uri.getQuery()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment