classMyQueue {privateStack<Integer> stack1 =newStack<Integer>();;privateStack<Integer> stack2 =newStack<Integer>();;privatevoidstack2ToStack1() {while (!stack2.isEmpty()) {stack1.push(stack2.pop()); } }// Push element x to the back of queue.publicvoidpush(int x) {stack2.push(x); }// Removes the element from in front of queue.publicvoidpop() {if (stack1.isEmpty()) {stack2ToStack1(); } stack1.pop(); }// Get the front element.publicintpeek() {if (stack1.isEmpty()) {stack2ToStack1(); } returnstack1.peek(); }// Return whether the queue is empty.publicbooleanempty() {returnstack1.isEmpty() &&stack2.isEmpty(); }}