how to find unique characters in a string in java

//  I would use linkedHashMap since it doesn't accept
//  duplicate values

String str = "abbcdddefffggghjilll";
        String [] arr = str.split("");
        Map<String, Integer> mapStr = new LinkedHashMap<>();

        for (int i=0 ; i < arr.length ; i++){
            if (!mapStr.containsKey(arr[i])){
                mapStr.put(arr[i],1);
            } else{
                mapStr.put(arr[i],mapStr.get(arr[i])+1);
            }
        }

        for (Map.Entry<String,Integer> map : mapStr.entrySet()) {
            if(map.getValue()==1) {
                System.out.print(map.getKey());
            }
        }

3.86
7
Hnephew 100 points

                                    public class String_FindtheUnique_4 {
/* Write a return  method that can find the unique characters from the String
 Ex:  unique(&quot;AAABBBCCCDEF&quot;)  ==&gt;  &quot;DEF&quot;;  */
    public static void main(String[] args) {

   String result1 = Unique(&quot;BBCCDDSSEEDDYUT&quot;);
   System.out.println(result1); // YUT

//1.yol 
    String s = &quot;BABABACDR&quot;;
    String r = &quot;&quot;;
    for(String each : s.split(&quot;&quot;))
 r += ( (Collections.frequency(Arrays.asList(s.split(&quot;&quot;)), each)) ==1 ) ? each : &quot;&quot;;
     System.out.println(r); // CDR
    }

//2.yol method yolu
  public static String Unique(String str) {
        String result1 =&quot;&quot;;
        for(String each : str.split(&quot;&quot;))
result1 += ( (Collections.frequency(Arrays.asList(str.split(&quot;&quot;)), each)) ==1 ) ? each : &quot;&quot;;
        return result1;
    }

}
  

3.86 (7 Votes)
0
4
8
Artde 70 points

                                    //  I would use linkedHashMap since it doesn't accept
//  duplicate values

String str = &quot;abbcdddefffggghjilll&quot;;
        String [] arr = str.split(&quot;&quot;);
        Map&lt;String, Integer&gt; mapStr = new LinkedHashMap&lt;&gt;();

        for (int i=0 ; i &lt; arr.length ; i++){
            if (!mapStr.containsKey(arr[i])){
                mapStr.put(arr[i],1);
            } else{
                mapStr.put(arr[i],mapStr.get(arr[i])+1);
            }
        }

        for (Map.Entry&lt;String,Integer&gt; map : mapStr.entrySet()) {
            if(map.getValue()==1) {
                System.out.print(map.getKey());
            }
        }

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
java unique strings java print string with unique characters check string element unique characters java java check unique(S) java check unique string number of unique characters in java how to get unique characters from string in java count unique values in a string java unique elements in a string java java uniques character what is unique about string in java program to print unique characters in a string in java store unique characters in string java java unique string find all unique characters in a string java find set of unique characters in a string java find the unique characters in a string using collections in java string find unique in java unique in java determine whether the string all unique letter in a name using java what is the basic logic to determine that a string has unique letters in java print all the unique characters in a name using java printing the unique character java program find unique from a string in java unique characters from a string in java string unique characters in java print unique character from the string in java find distinct letters in string java find the unique characters in a string java how to find unique characters in string in java counting unique characters in a string java number of unique letters in string java java find unique characters in string finding unique characters in a string java finfing unique element in 2 string java unique character java unique characters in string java java string get all unique chars set java String to unique char unique characters in a string java identify unique char in string java in sequence identify unique char in string java java program to find unique characters in a string string unique characters java java find distinct characters in a string java program to find unique words in a string how to find unique characters in a line in java get unique values in java in string string with unique characters java check for unique characters in string java java program to print unique characters in a sentence print unique characters in a string in java find unique characters in string java unique character present in string java unique character in string java program to find unique characters in a string in java java string all char are unique java find unique chars in string how to find number of unique characters in a string in java unique letter in string java java unique characters in string get unique characters in string java how to determine if string has all unique characters unique string in java Write an algorithm that determines whether all the elements in a string are unique recursion unique words in string java list of unique chars from string java number of disnict characters of a string proreadr.in string with unique characters find unique characters in a string java how to print unique characters in a sentence in java how to find the unique character how to find unique characters in a string in java find unique characters in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source