Answers for "Unique character from String map"

1

Unique character from String map

Map -- Unique character from String
public static void main(String[] args) {

    String str = "accabbcd";
    Map<Character, Integer> unique = new HashMap<>();

    for( int j = 0; j < str.length(); j++) {
        int count =0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) == str.charAt(j))
                count++;
        }
        if( count == 1){
            unique.put(str.charAt(j), count);
        }
    }

    System.out.println(unique);

}
Posted by: Guest on September-29-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language