How to check if TreeMap> contains a value? in Java

前端 未结 3 449
刺人心
刺人心 2021-01-28 14:39

I\'m just wondering how to check if TreeMap> contains a value in Java? For Example:

/*I have TreeMap> map with these element         


        
3条回答
  •  迷失自我
    2021-01-28 15:07

    You're testing to see whether the map contains a String, "square"-- but the values in your map are ArrayList objects.

    If you know that you're looking for a shape, you can first get the "shape" list, and test to see whether it contains the specific shape "square".

      ArrayList shapes = map.get("shape");
      boolean containsSquare = shapes.contains("square");
    

提交回复
热议问题