confused, hashmaps dont allow duplicates, how can i check if they have the same fiurst or last name?
package com.codegym.task.task08.task0815;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
/*
Longest sequence
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<String, String>();
map.put("kumar", "swami");
map.put("verma", "gaurav");
map.put("singh", "tarun");
map.put("yadav", "sonam");
map.put("kaushik", "sunil");
map.put("rathor", "sonali");
map.put("deyol", "raj");
map.put("ping", "suresh");
map.put("sheran", "satish");
map.put("huda", "swaminarayan");
return map;
}
public static int getSameFirstNameCount(HashMap<String, String> map, String name) {
int fristname = 0;
Iterator<Entry<String, String>> it1 = map.entrySet().iterator();
while (it1.hasNext()){
if(it1.next().equals(name)) {
fristname++;
}
}
//write your code here
return fristname;
}
public static int getSameLastNameCount(HashMap<String, String> map, String lastName) {
int sameLastNameCount = 0;
Iterator<Entry<String, String>> it1 = map.entrySet().iterator();
while (it1.hasNext()) {
if (it1.next().equals(lastName))
sameLastNameCount++;
}
sameLastNameCount = 0;
return sameLastNameCount;
//write your code here
}
public static void main(String[] args) {
HashMap<String, String> map = createMap();
//System.out.println(map);
//System.out.println();
}
}