Home » Java » hashmap – HashSet contains not working for Set of Long in Java only for some specific values?-Exceptionshub

hashmap – HashSet contains not working for Set of Long in Java only for some specific values?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to execute the below code :

for (Map.Entry<Long, List<FieldBO>> sectionField : sectionFieldMap.entrySet()) {
  if (secIds.contains(Long.valueOf(sectionField.getKey()))) {
//////

Here secIds is a Set which I am getting from the database. But here contains is only working for a few Ids.
SecIds contains values [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]. Contains is giving true for 54, 55, 56, 57, 58, 59 but for other values even if I am checking with same like 64,65 etc which is present in secIds I am getting false. Please help me find why this is happening ?

NB: Please do not mark this as a duplicate there is no question/answer for this specific issue.

How to&Answers: