public ArrayList<ArrayList<String>> partition(String s) {
        ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
        if(s.equals(""))
            return result;
        result.add(new ArrayList<String>());
        for(int i = 0; i < s.length(); i++){
            ArrayList<ArrayList<String>> copyResult = new ArrayList<ArrayList<String>>();
            copyResult.addAll(result);
            for(ArrayList<String> item: copyResult){

                int size = item.size();
                if(size >= 2 && isPalindrome(item.get(size - 2) + item.get(size - 1) + s.substring(i, i+1))){
                    ArrayList<String> arrayList1 = new ArrayList<String>();
                    arrayList1.addAll(item);
                    arrayList1.remove(size - 1);
                    arrayList1.remove(size - 2);
                    arrayList1.add(item.get(size - 2) + item.get(size - 1) + s.substring(i, i+1));
                    if(!result.contains(arrayList1))
                        result.add(arrayList1);
                }
                if(size >= 1 && isPalindrome(item.get(size - 1) + s.substring(i, i+1))){
                    ArrayList<String> arrayList1 = new ArrayList<String>();
                    arrayList1.addAll(item);
                    arrayList1.remove(size - 1);
                    arrayList1.add(item.get(size - 1) + s.substring(i, i + 1));
                    if(!result.contains(arrayList1))
                        result.add(arrayList1);
                }
                item.add(s.substring(i, i+1));
            }
        }
        return result;
    }