Does java sdk have a method to complete a workflow without calling all activities?

Hi,

I have a workflow which runs activities in order A → B → C → D
Does java sdk support a method so that the workflow can complete execution after activity B ?

If the logic to stop exec after activity X something pre-determined by the client that starts workflow execution (for example via workflow data input) or is it part of your workflow business logic (for example on activity failure)?

Not necessarily activity failure, basically I want to check for if (condition) in activity if thats true then skip the remaining activities and complete the workflow.

Workflow execution ends when the @WorkflowMethod completes.
I think one way is for your activity to return a result that indicates that workflow execution should stop, then have the if condition inside the workflow that based on the activity result can just return or continue execution.
Another possible way I can think of would be to terminate the workflow from the activity.
In activities you can use the client api, and can get the workflow id, type, and namespace via
Activity.getExecutionContext().getInfo().