Recursion - all subsequnce challenge

output is perfect but not in order help ASAP
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String str = “ab”;

	sub(str, "");
}
public static void sub(String str, String result)
{
	//base case
	if(str.length()==0)
	{
		System.out.println(result);
		return;
	}
	
		char ch = str.charAt(0);
		String ros = str.substring(1);

		sub(ros,result+ch);
		sub(ros,result);
		
	
	
}

}

@Naman_Gupta,
Store the subsequences in an arraylist. And return the arraylist. Then sort the arraylist and print.

so we havw to use the get recursion approach by creating and storing it in arraylist

@Naman_Gupta,
Instead of printing, store the subsequences in an arraylist. And then finally return the arraylist. After that sort the arraylist and print the elements in the arraylist.

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.