-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElection.java
More file actions
35 lines (24 loc) · 996 Bytes
/
Election.java
File metadata and controls
35 lines (24 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package intro;
import java.util.*;
public class Election {
public static void main(String[] args) {
// TODO Auto-generated method stub
String [] someArray = new String[]{"john", "johnny", "jackie", "johnny","john" ,"jackie", "jamie" ,"jamie" ,"john", "johnny" ,"jamie", "johnny", "john"};
Map<Integer,String> repeatationMap= new HashMap<Integer,String>();
for(String str : someArray){
if(repeatationMap.containsKey(str)) {
int ind = repeatationMap.hashCode() + 1;
repeatationMap.put(ind,str);
}
else {
repeatationMap.put(1,str);
}
}
Set set = repeatationMap.entrySet();
Iterator iterator2 = set.iterator();
while(iterator2.hasNext()) {
Map.Entry me2 = (Map.Entry)iterator2.next();
System.out.println("Election result: " + me2.getKey());
}
}
}