You would usually use an explicit state machine for that. The idea is that you have a variable that stores the current state (say: animation A). And when that animation finishes you update the state variable to a new state (say: animation B).
Then, in your loop, when playing animations, you have a switch satement that selects a case depending on the state variable, and then that case handles the logic for that state.
There are more advance solutions, of course. You might create your state machine as a tree, where each state has sub-states. You may represent them as data (they are not a bunch of switch statements, but dictionaries). Or you could use full-fledged behavior tree.
Alternatively, you might also use coroutines. A common trick is to implement them as iterators (each loop you pull a new item, and the logic is in the iterator), then you can build an implicit state machine around them.
And of course, you can mix and match. For example, have a state machine that picks a behavior tree.
There are also libraries that help you implement all that, you may want to have a look around. I do not really develop in Java. So, I can’t really recommend.