0
HashMap<String, List<String>> filterableMap = new HashMap<>();

    filterableMap.put("department", Arrays.asList("A","B",null));
    filterableMap.put("group", Arrays.asList("C","D",null));       

From the above map i need to dynamically build a queryString like show below.

"SomeURL"/token/filter?department=A&department=B&group=C&group=D

I just used Hashmap we can use any thing as long as we can hold the values in name value pair.

for (Map.Entry<String, List<String>> entry : filterableMap.entrySet()) {
        String key = entry.getKey();
        List<String> value = entry.getValue();

        for(String aString : value){
            System.out.println("key : " + key + " value : " + aString);
            if("department".equalsIgnoreCase(key)) {
               qStrBulderBuilder.append("department =");
               qStrBulderBuilder.append(value);

            }

        }
    }

I am using like above approach , but i need to make sure i need put "=" and "&" in the right places some times we may not get "department" or "group"

user2045474
  • 135
  • 1
  • 9
  • 1
    Read how to use foreach and keyset in hashmap [this](http://stackoverflow.com/questions/14149984/for-each-loop-on-java-hashmap) [this](http://stackoverflow.com/questions/4234985/how-to-for-each-the-hashmap) [this](http://stackoverflow.com/questions/46898/iterate-over-each-entry-in-a-map) and read [this](http://java67.blogspot.in/2014/05/3-examples-to-loop-map-in-java-foreach.html) – Madhan Jun 27 '15 at 14:48
  • To build the URI. maybe you can use something like: https://github.com/Mashape/unirest-java, isn't it? – facundofarias Jun 27 '15 at 18:14
  • 1
    If you're running in a Java EE container, you probably should use [UriBuilder](http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html). – VGR Jun 27 '15 at 19:47

0 Answers0