como reverter uma pilha usando outra pilha em java [closed]

Oi, eu estou tentando reverter uma pilha (um que eu me codifiquei) usando outra pilha vazia. Por alguma razão, não está funcionando corretamente. Alguém pode me ajudar com isso ?

public static void main(String[] args) {

    Stack stack1 = new Stack();

        //filling the stack with numbers from 0 to 4
        for(int i = 0; i < Constants.MAX_ELMNTS; i++){

            stack1.push(new Integer(i));
            System.out.println(i);
    }   


    Stack reverse = new Stack();

    while(stack1.getNbElements() > 0){

        reverse.push(stack1.pop());
    }

questionAnswers(1)

yourAnswerToTheQuestion