Recursion dictionary order(larger) problem-why getting wrong output?

package Recursion;
import java.util.*;
public class Dic {

public static void main(String args[]){
	
	Scanner scan = new Scanner(System.in);
	String input = scan.next();
	char c[] = input.toCharArray();
	
	Arrays.sort(c);
	
	String s = new String(c);
//System.out.println(s);
	ArrayList<String> ans =	getper(s);
	int p=0;
		
	
	for(int i=0;i<ans.size();i++)
	{
		String caa =ans.get(i);
		if((caa.compareTo(input))>0 )
		{
			p=i;
			break;
		
		}
}
	for(int i=p;i<ans.size();i++)
	{
		System.out.println(ans.get(i));
	}
	}

public static ArrayList<String> getper(String str)

{
	
	if(str.length()==0)
	{
		ArrayList<String> br = new ArrayList<>();
		br.add(" ");
		return br;
	}
	char cc = str.charAt(0);
	String ros = str.substring(1);
	
	ArrayList<String> result = new ArrayList<>();
	ArrayList<String> rr = getper(ros);
	
	for(String rrs:rr)
	{
	for(int i=0;i<rrs.length();i++)
	{
		
		result.add(rrs.substring(0, i)+cc+rrs.substring(i));
	}
	}
	return result;
}

}

Hi,you have to get the answers in lexico order.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.