how to find unique characters in a string in java

Solutions on MaxInterview for how to find unique characters in a string in java by the best coders in the world

showing results for - "how to find unique characters in a string in java"
Monica
29 Apr 2016
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        }
Lotta
06 Apr 2017
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  
Nail
21 Aug 2016
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
queries leading to this page
unique character javaprogram to find unique characters in a string in javanumber of unique letters in string javaidentify unique char in string java in sequencejava program to find unique words in a stringfind unique characters in string javastore unique characters in string javajava check unique stringunique characters from a string in javaget unique values in java in stringfind all distinct character in substring of string javajava how to look for a unique letterunique characters in a string javadetermine whether the string all unique letter in a name using javafind unique characters in a string javajava print string with unique charactershow to check if string has all unique characters in javafind all unique characters in a string javacode tot print unique characters in javahow to create a unique string in javawhat is unique about string in javaget unique chars from string javacounting unique characters in a string javastring unique characters in javaproreadr in string with unique charactersfind distinct substring in string javaunique char javastring find unique in javajava string unique characters inbuilt methodjava check unique 28s 29check for unique characters in string javahow to determine if string has all unique charactershow to find unique characters in a line in javafind distinct letters in string javachecking if all the characters are unique in a string javaunique elements in a string javafinding unique characters in a string javaprint unique characters in a string in javanumber of unique characters in javahow to find number of unique characters in a string in javajava unique stringsstring with unique characters javawrite an algorithm that determines whether all the elements in a string are unique recursioncount unique words in string javahow to find number of unique characters in a stringhow to find the unique characterjava string unique charactersget all unique characters in string javaidentify unique char in string javaunique words in string in javaunique letter in string javaget unique characters in string javafinfing unique element in 2 string javanumber of disnict characters of a stringa unique string in javafind unique words in string javajava unique characters in stringfind set of unique characters in a string javaprint all the unique characters in a name using javaunique words in string javahow to find unique characters in a string in javacount distinct characters in a string javahow to get unique characters from string in javajava find unique characters in stringjava string to unique charstring unique characters javacheck for the unique characters in string javaunique character present in string javajava find distinct characters in a stringprint all unique characters in a string javacheck string element unique characters javafind unique from a string in javajava string get all unique chars setfind the unique characters in a string javafind number of unique in string javafind the unique characters in a string using collections in javawhat is the basic logic to determine that a string has unique letters in javahow to find unique characters in string in javawrite a java program to find out if the given string has all unique charactersfind unique characters in javacode to print unique characters in javaprint unique character from the string in javajava string all char are uniqueunique string in javalist of unique chars from string javahow to print unique characters in a sentence in javaunique in javaprogram to print unique characters in a string in javaprinting the unique character java programunique character in string javaget unique characters in string java codejava unique stringjava program to find unique characters in a stringjava uniques characterunique characters in string javacount unique values in a string javajava program to print unique characters in a sentencejava find unique chars in stringjava count distinct characters in a stringfind all unique char in string javahow to find unique characters in a string in java