For Explanation watch the video:
code :
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef{
public static void main(String[] args){
String s = "abcdABCDabcd";
Map<Character,Integer> hm = new HashMap<>();
for(int i=0;i<s.length();i++){
Character ch = s.charAt(i);
hm.put(ch,hm.getOrDefault(ch,0)+1);
}
System.out.println(hm);
}
}
output :