Implementing a queue using three stacks
import java.util.Stack;

public class StackQueue&lt;T&gt; {
    private Stack&lt;T&gt; writeStack = new Stack&lt;T&gt;();
    private Stack&lt;T&gt; readStack = new Stack&lt;T&gt;();

    public void enqueue(T element) {
        writeStack.push(element);
    }

    public T dequeue(){
        if (readStack.empty()) {
            while (!writeStack.empty()) {
                readStack.push(writeStack.pop());
            }
        }
        return readStack.pop();
    }
}


Algorithm

You only need two stacks. Always write to the writeStack, read from the readStack. If the latter is empty, copy everything over.

Naming

Use meaningful names, such as writeStack and readStack instead of stack1 and stack2. Declare them private. A queue's user doesn't care about the internals. Import only what you need, in this case java.util.Stack.

Generics

The Stack&lt;T&gt; is a generic datatype, make use of it. Make your StackQueue generic as well. Instanciate it using

StackQueue&lt;String&gt; queue = new StackQueue&lt;String&gt;();


Return value

dequeue() should return a value. Print it with

System.out.println(queue.dequeue());