1

I have a LinkedHashMap<String, ArrayList<String>>.

By default, all of the values are populated with a " " and there are three keys

I want to check if any of the values for any of the three keys is not equal to a " ".

This is what I have done so far ` boolean checkMapContent(LinkedHashMap> Map) {

    for (Map.Entry<String, ArrayList<String>> entry : Map.entrySet())
     {
        String key = entry.getKey();

        ArrayList<String> labelValue = entry.getValue();
        for (String entry1 : labelValue)
        {
            if (!entry1.equals(" ")) 
            {
                return false;
            }
        }
     }
    return true;
}`

2 Answers2

0

You can try this:

public boolean hasNotEmpty(LinkedHashMap<String,ArrayList<String>> map) {
        for (ArrayList<String> list: map.values()) {
            for (String str: list)
                if (!str.equals(" "))
                    return true;
        }

        return false;
    }
Gregory Prescott
  • 574
  • 3
  • 10
  • This returns true if he has a list that has " ", "something" and false if he has a list that has "something", "something". I'm fairly sure that's not what OP is asking. – Neil Mar 09 '16 at 09:51
  • Ok, it isn't *wrong* per se, so I'll remove downvote. – Neil Mar 09 '16 at 09:55
-2
for(LinkedHashMap<String,ArrayList<String>> l1:mapName.entrySet())
{
   ArrayList<String> a1=l1.getValue();

  if(!a1.contains(" "))
    //do something 

 }
user1613360
  • 1,280
  • 3
  • 16
  • 42
  • This won't even compile. The key isn't an `ArrayList`, it is a `String`, and the `//do something` should be part of your answer. – Neil Mar 09 '16 at 09:31
  • @Neil my bad and do something is there because the user didn't specify what he wants to do once a match occurs. – user1613360 Mar 09 '16 at 09:42
  • I'm guessing that he means to return true or false according to whether or not it contains a non-space value. What he does with that boolean is entirely up to th OP. It doesn't have to be in the same place. :P – Neil Mar 09 '16 at 09:50