I want to change my start navigation fragment based on a condition. My start fragment could be fragment one or two. Is there a way to implement it?

I want to change my start navigation fragment based on a condition. My start fragment could be fragment one or two. Is there a way to implement it?

 
    
     
    
    Check out this question and its solution // Also added Java code here
Just converted Kotlin code to Java
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.home_nav_fragment);  // Hostfragment
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
NavGraph graph = inflater.inflate(R.navigation.nav_main);
graph.setDefaultArguments(getIntent().getExtras());
graph.setStartDestination(R.id.fragment1);
navHostFragment.getNavController().setGraph(graph);
navHostFragment.getNavController().getGraph().setDefaultArguments(getIntent().getExtras());
NavigationView navigationView = findViewById(R.id.navigationView);
NavigationUI.setupWithNavController(navigationView, navHostFragment.getNavController());
 
    
     
    
    Check out this question and it's solution
I have also added a comment below the answer to clear it up a bit.
