Implementing two stacks using single array in java
I would go for

interface Stack {
    boolean isEmpty();
    int pop();
    void push(int x);
}


And then make a class providing two Stacks.

Also create a counter to detect when both stacks are full. This can be done with an AtomicInteger (thread-safeness) counting the free array slots.

public class StackPair {
    public final Stack firstStack = new Stack { ... };
    public final Stack secondStack = new Stack { ... };
    public StackPair(int capacity) { ... }




In StackPair the single array and an AtomicInteger freeEntries. In both Stack implementations access to the array and freeEntries.