-2

I have Hashmap (which basically has api response body). I'm trying to extract a particular value from it.

for(Entry<String, Object> i: response.entrySet()) {
            System.out.println("Inside for loop "+i.getValue()); //1st Line
            if(i.getValue().equals("A") ||i.getValue().equals("B")) {
                System.out.println("Inside if true "); //Q) Why does it not go inside this if loop
            }
        }

If I debug, I get 'response' value (this is api response body) :

{content={id=12345, Status=A, onLine=true}}

The output for above for loop I'm getting as: (for 1st line only)

Inside for loop {id=12345, Status=A, onLine=true}

But how do I just get the value for Status?

Note- This is how the content of keys and values are

(id,"12345")
(Status,"A")
(onLine,true)

In some cases key Status can have different values like "A", "B", "C" etc. And this is why I would like to perform certain steps when the value for Status is either "A" or "B".

2nd Edit- Additionally I have also tried

response.containsValue("A")

But I'm not able to filter out the content.

stuart
  • 33
  • 6
  • 2
    Because (all together now) "that's not the correct way to compare Strings". See this: https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – dangling else May 26 '22 at 02:20
  • Your Question is unclear. Exactly what is the content of the keys and values in your map? Did you mean to compare the `String` key to `A`/`B` rather than the `Object` value? – Basil Bourque May 26 '22 at 02:31
  • @BasilBourque I have added the keys and values content. I would like to filter situation when the key Status has certain value like "A" or "B" and then perform certain steps. – stuart May 26 '22 at 13:19
  • Just a wild guess -- what if you tried something like `i.getValue().Status.equals("A")`? – belwood May 27 '22 at 11:44

0 Answers0