Queue By Using Stack I have implemented a queue by using a stack data structure. How could I improve it?

package _amazonAskedQuestions.dataStructures;

import java.util.Iterator;
import java.util.Stack;

public class Queue_Stack&lt;T&gt; implements  Iterable&lt;T&gt;{

    Stack&lt;T&gt; stack = new Stack&lt;&gt;();

    public void enqueue(T item){
        Stack&lt;Integer&gt; temp = new Stack&lt;Integer&gt;();
        while(!stack.empty()){
            temp.push((Integer) stack.pop());
        }
        stack.push(item);
        while(!temp.empty()){
            stack.push((T) temp.pop());
        }
    }

    public T dequeue(){
        return stack.pop();

    }

    @Override
    public Iterator&lt;T&gt; iterator() {
        return (Iterator&lt;T&gt;) stack.lastElement();
    }


    public static void main(String args[]){

        Queue_Stack&lt;Integer&gt;  qs = new Queue_Stack&lt;&gt;();

        qs.enqueue(9);
        qs.enqueue(8);
        qs.enqueue(1);
        qs.enqueue(3);
        qs.enqueue(4);
        qs.enqueue(5);

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

    }
}
Your Queue_Stack only works with Integer.  I tried using String and got a ClassCastException.

I made some modifications to your code.  I added a test to make sure you don't get an error if you dequeue more than you enqueue.  I used the underlying iterator to get rid of the temp Stack.

import java.util.Iterator;
import java.util.Optional;
import java.util.Stack;

public class Queue_Stack&lt;T&gt; implements Iterable&lt;T&gt; {

    Stack&lt;T&gt; stack = new Stack&lt;&gt;();

    public void enqueue(T item) {
        stack.push(item);
    }

    public Optional&lt;T&gt; dequeue() {
        if (!stack.empty()) {
            T item = stack.iterator().next();
            stack.remove(0);
            return Optional.of(item);
        } else {
            return Optional.empty();
        }
    }

    @Override
    public Iterator&lt;T&gt; iterator() {
        return (Iterator&lt;T&gt;) stack.iterator();
    }

    public static void main(String args[]) {
        Queue_Stack&lt;String&gt; qs = new Queue_Stack&lt;&gt;();

        qs.enqueue("zeta");
        qs.enqueue("alpha");
        qs.enqueue("beta");
        qs.enqueue("gamma");

        Iterator&lt;String&gt; iter = qs.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }

        System.out.println(qs.dequeue());
        System.out.println(qs.dequeue());
        System.out.println(qs.dequeue());
        System.out.println(qs.dequeue());
        System.out.println(qs.dequeue());
    }
}