Maximum length of string formed by concatenation having even frequency of each character

  import java.io.*;import java.util.*;  public class index {    static int max = 0;    static String ans1 = “”;          static void calculate(String ans)    {          int dp[] = new int[26];        for (int i = 0; i < ans.length(); ++i) {                                      dp[ans.charAt(i) - 'A']++;        }                  for (int i = 0; i < dp.length; ++i) {            if (dp[i] % 2 == 1) {                return;            }        }        if (max < ans.length()) {                                      max = ans.length();            ans1 = ans;        }    }                  static void longestString(        List arr, int index, String str)    {                  if (index == arr.size()) {            return;        }                  longestString(arr, index + 1, str);                  str += arr.get(index);          calculate(str);        longestString(arr, index + 1, str);    }          public static void main(String[] args)    {        ArrayList A = new ArrayList();        A.add("ABAB");        A.add("ABF");        A.add("CDA");        A.add("AD");        A.add("CCC");                  longestString(A, 0, "");                  System.out.println(ans1 + " "                           + ans1.length());    }}