# Occurrence of value in a map

Page 1 of 1

## 4 Replies - 1025 Views - Last Post: 05 August 2016 - 04:22 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=395942&amp;s=daa27f162321d41ba2726a8524a9f74e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 alinabb

Reputation: 0
• Posts: 35
• Joined: 02-August 16

# Occurrence of value in a map

Posted 04 August 2016 - 12:06 PM

public Map<String ,Car> combination(Map<String ,Car> carMap){

for(Map.Entry<String, Car> entry : qualMap.entrySet()){

Car carTemp = entry.getValue();

for(CarDetails temp : carTemp.getCarDetails()){
if(Constants.VOLSWAGEN.equals(temp.getBrand) && Integer.parseInt(temp.getRank) <= 25){
if (totalRank >= 9){
carTemp.setStatus("VALID");
}
else if (totalRank >= 10 && totalPass >= 1){
carTemp.setStatus("VALID");
}

else{
carTemp.setStatus("INVALID");
}
}
carTemp.setStatus("INVALID");
}

}

The size of my map will be either 1 or 2. So I can have these combination:
1. Valid
2. Invalid
3. Valid , Valid
4. Valid , invalid or vice versa
5. Invalid , Invalid

My question is , at the end of the for loop, i need to know if the map contain 2 invalid records , in order to do some processing. What is the best way to do this? (I can override the key if needed)

Is This A Good Question/Topic? 0

## Replies To: Occurrence of value in a map

### #2 NormR

• D.I.C Lover

Reputation: 796
• Posts: 6,040
• Joined: 25-December 13

## Re: Occurrence of value in a map

Posted 04 August 2016 - 12:18 PM

Quote

i need to know if the map contain 2 invalid records

Can you use a variable to count the number of invalid records?

### #3 alinabb

Reputation: 0
• Posts: 35
• Joined: 02-August 16

## Re: Occurrence of value in a map

Posted 04 August 2016 - 09:41 PM

NormR, on 04 August 2016 - 12:18 PM, said:

Quote

i need to know if the map contain 2 invalid records

Can you use a variable to count the number of invalid records?

it won't work. since the list carTemp.getCarDetails() will contain only one record with volswagen. So I need to check the rank of the volswagen first.

### #4 NormR

• D.I.C Lover

Reputation: 796
• Posts: 6,040
• Joined: 25-December 13

## Re: Occurrence of value in a map

Posted 05 August 2016 - 03:18 AM

Quote

need to know if the map contain 2 invalid records

I don't know of any other ways to know if the map has 2 invalid records other than to count them.

Why do you think that won't work?

### #5 g00se

• D.I.C Lover

Reputation: 3643
• Posts: 16,753
• Joined: 20-September 08

## Re: Occurrence of value in a map

Posted 05 August 2016 - 04:22 AM

Quote

carTemp.setStatus("INVALID");

Your code is badly indented but it looks to me that the last occurrence of the above overrides anything preceding it