Not passing all test cases

Can you say where I am doing wrong?

this is my code

import java.util.*;
public class Main
{
public static ArrayList perm(String s)
{
if(s.length()==0)
{
ArrayList br=new ArrayList<>();
br.add("");
return br;
}
char ch=s.charAt(0);
String s1=s.substring(1);
ArrayList mr=new ArrayList<>();
ArrayList rr=perm(s1);
for(String a : rr)
{
if(!mr.contains(ch+a))
mr.add(ch+a);
if(!mr.contains(a+ch))
mr.add(a+ch);
}
return mr;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
ArrayList re=perm(s);
Collections.sort(re);
for(String q : re)
System.out.println(q);

}

}

Instead of adding elements to the arraylist and then sorting it before printing.

convert the string to a char array. Sort the char array. And then just print the permutations. In this you will save a lot of computation. And the permutations will be sorted