find unique characters in java

Solutions on MaxInterview for find unique characters in java by the best coders in the world

showing results for - "find unique characters in java"
Briony
08 Sep 2017
1//  I would use linkedHashMap since it doesn't accept
2//  duplicate values
3
4String str = "abbcdddefffggghjilll";
5        String [] arr = str.split("");
6        Map<String, Integer> mapStr = new LinkedHashMap<>();
7
8        for (int i=0 ; i < arr.length ; i++){
9            if (!mapStr.containsKey(arr[i])){
10                mapStr.put(arr[i],1);
11            } else{
12                mapStr.put(arr[i],mapStr.get(arr[i])+1);
13            }
14        }
15
16        for (Map.Entry<String,Integer> map : mapStr.entrySet()) {
17            if(map.getValue()==1) {
18                System.out.print(map.getKey());
19            }
20        }
21