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 }
1public class String_FindtheUnique_4 {
2/* Write a return method that can find the unique characters from the String
3 Ex: unique("AAABBBCCCDEF") ==> "DEF"; */
4 public static void main(String[] args) {
5
6 String result1 = Unique("BBCCDDSSEEDDYUT");
7 System.out.println(result1); // YUT
8
9//1.yol
10 String s = "BABABACDR";
11 String r = "";
12 for(String each : s.split(""))
13 r += ( (Collections.frequency(Arrays.asList(s.split("")), each)) ==1 ) ? each : "";
14 System.out.println(r); // CDR
15 }
16
17//2.yol method yolu
18 public static String Unique(String str) {
19 String result1 ="";
20 for(String each : str.split(""))
21result1 += ( (Collections.frequency(Arrays.asList(str.split("")), each)) ==1 ) ? each : "";
22 return result1;
23 }
24
25}
26
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