content: import java.util.ArrayList;
  import java.util.List;
  
  public class PalindromePartitioning {
      public static List<List<String>> partition(String s) {
          List<List<String>> result = new ArrayList<>();
          List<String> current = new ArrayList<>();
          backtrack(result, current, s, 0);
          return result;
      }
      
      private static void backtrack(List<List<String>> result, List<String> current, String s, int start) {
          if (start == s.length()) {
              result.add(new ArrayList<>(current));
              return;
          }
          
          for (int end = start; end < s.length(); end++) {
              if (isPalindrome(s, start, end)) {
                  current.add(s.substring(start, end + 1));
                  backtrack(result, current, s, end + 1);
                  current.remove(current.size() - 1);
              }
          }
      }
      
      private static boolean isPalindrome(String s, int start, int end) {
          while (start < end) {
              if (s.charAt(start) != s.charAt(end)) {
                  return false;
              }
              start++;
              end--;
          }
          return true;
      }
      
      public static void main(String[] args) {
          String input = "aab";
          List<List<String>> partitions = partition(input);
          
          for (List<String> partition : partitions) {
              System.out.println(partition);
          }
      }
  }
  