Storing key-value(s) pairs and iterating through it using java

Sreejith22 used Ask the Experts™
Hi experts,

I have a set of key-values in the following format (id1, value1,value2,value3...) , (id2, value1,value2,value3...) and so on.

I need to store this in some java variable(collection object?).

After this, at a later point, I need to compare the values corresponding to each id above with the values contained in another String array. Whenever a match is found it should break.

How should I go about doing this/ What is the best method using which this can be accomplished with the most suitable data type for the kind of key value pair structure shown above?

Any help with some small simulated demo code snippet is much appreciated.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hashmap<String, List<String>>

first string param : key
Second list param: list of values


How to iterate through the values to compare them with strings in another array?
<<How to iterate through the values to compare them with strings in another array?>>
Just iterate through the list of string

List<String> values = map.get(id);

// convert another array to list
List<String> lList = Arrays.asList(sArray)

Iterator<String> iterator = lList.iterator();
      while (iterator.hasNext()) {
            String value =;
               //now check if this list is in the values list
              if ( values.contains(value) )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial