unique character from string map

Solutions on MaxInterview for unique character from string map by the best coders in the world

showing results for - "unique character from string map"
Lilly
23 Jun 2016
1Map -- Unique character from String
2public static void main(String[] args) {
3
4    String str = "accabbcd";
5    Map<Character, Integer> unique = new HashMap<>();
6
7    for( int j = 0; j < str.length(); j++) {
8        int count =0;
9        for (int i = 0; i < str.length(); i++) {
10            if(str.charAt(i) == str.charAt(j))
11                count++;
12        }
13        if( count == 1){
14            unique.put(str.charAt(j), count);
15        }
16    }
17
18    System.out.println(unique);
19
20}