-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
25 lines (18 loc) · 706 Bytes
/
Test.java
File metadata and controls
25 lines (18 loc) · 706 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
package com.interview.mphasis;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) {
String str = "Bangalore Bangalore Pune Mumbai Delhi Noida Pune Pune";
String[] strArray = str.split(" ");
List<String> list = Arrays.asList(strArray);
//List<String> list = Arrays.asList("Bangalore", "Bangalore", "Pune", "Mumbai", "Delhi", "Noida", "Pune", "Pune");
Set<String> st = new HashSet<String>(list);
// here set we are using for only print the unique character
for (String s : st)
System.out.println(s + ": " + Collections.frequency(list, s));
}
}