code: private double calcEntropy(String str) {
  
      HashMap<Character, Integer> freq = new HashMap<>();
      for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        Integer count = freq.get(c);
        if (count == null) freq.put(c, 1);
        else freq.put(c, count + 1);
      }
      double sume = 0;
      int N = str.length();
      double n;
      for (char c : freq.keySet()) {
        n = freq.get(c);
        sume += -n / N * Math.log(n / N) / Math.log(2);
      }
      return sume;
    }
docs: Shannon's entropy