Check if a string can be made palindromic by swapping pairs of characters from indices having unequal characters in a Binary String

  import java.io.*;import java.util.HashMap;import java.util.HashSet;import java.util.Map;  class GFG {              public static boolean    canBecomePalindromeUtil(String S,                            String B)    {                        HashSet set = new HashSet();                  for (int i = 0; i < S.length(); i++) {                          set.add(S.charAt(i));        }                          HashMap map            = new HashMap();                  for (int i = 0; i < S.length(); i++) {            Integer k = map.get(S.charAt(i));            map.put(S.charAt(i),                    (k == null) ? 1 : k + 1);        }          boolean flag = false;                  if (S.length() % 2 == 1) {                                                  int count1 = 0, count2 = 0;              for (Map.Entry e :                 map.entrySet()) {                  if (e.getValue() % 2 == 1) {                                                              count2++;                }                else {                                                              count1++;                }            }                          if (count1 == set.size() - 1                && count2 == 1) {                flag = true;            }        }                  else {                                                  int count1 = 0, count2 = 0;              for (Map.Entry e :                 map.entrySet()) {                  if (e.getValue() % 2 == 1) {                                                              count2++;                }                else {                                                              count1++;                }            }                          if (count1 == set.size()                && count2 == 0) {                flag = true;            }        }                          if (!flag) {            return false;        }          else {                                      int count1 = 0, count0 = 0;            for (int i = 0;                 i < B.length(); i++) {                                  if (B.charAt(i) == '1') {                    count1++;                }                else {                    count0++;                }            }                          if (count1 >= 1 && count0 >= 1) {                return true;            }              else {                return false;            }        }    }                  public static void    canBecomePalindrome(String S,                        String B)    {        if (canBecomePalindromeUtil(S, B))            System.out.print(“Yes”);        else            System.out.print(“No”);    }          public static void main(String[] args)    {        String S = “ACABB”;        String B = “00010”;        canBecomePalindrome(S, B);    }}