Skip to content

Instantly share code, notes, and snippets.

@leifoolsen
Last active August 29, 2015 14:18
Show Gist options
  • Save leifoolsen/3f29e42d1451d8e97165 to your computer and use it in GitHub Desktop.
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.
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