forked from puruagarwal1/hacktoberfest-2022-directory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetEntry.java
More file actions
34 lines (30 loc) · 701 Bytes
/
SetEntry.java
File metadata and controls
34 lines (30 loc) · 701 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
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class SetEntryExample
{
public static void main(String[] args)
{
String[] s= {"Apple","Banana","Guvav","Apple","Orange"};
List<String> list=Arrays.asList(s);
Map<String,Integer> map=new HashMap<>();
for(String so:list)
{
if(map.containsKey(so))
{
map.put(so, map.get(so)+1);
}else
{
map.put(so, 1);
}
}
Set<Entry<String, Integer>> entry= map.entrySet();
for(Entry<String, Integer> pp:entry)
{
System.out.println(pp.getKey()+" : "+pp.getValue() );
}
}
}