Sort stack using two stacks
Generic type declaration

Your Stacks are missing the type parameter, i.e. in your case Stack&lt;Integer&gt;. This ensures they can only contain Integer objects.

static vs instance fields

sorted is the only instance field used in the only method of your SortStack class. This means it is likely better to exist as a method variable, and in turn your SortStack class becomes an utility class where sort(Stack&lt;Integer&gt; input) is now a static utility method.

Primitive unboxing

On a related note to the first point, you are implicitly relying on primitive unboxing, i.e. converting an Integer to int when you do this:

int temp1 = (int) unsorted.pop();


If a null is lurking in your unsorted object, this will fail.

Debugging and variable naming

If possible, use a logging framework like SLF4J so that you can configure when you want to see the debug statements, instead of simply printing via System.out.println(). Also:

" pushed from s1 to s2"


Isn't that meaningful - is s1 or s2 the sorted one? You may want to specify that. Same goes for temp1 and temp2, it's not possible to identify which contains the previous/current iterative element from the unsorted or sorted stack.

Future considerations

If you don't want to restrict to sorting Stack&lt;Integer&gt; objects, you can generic-fy it as such:

public static &lt;T&gt; sort(Stack&lt;T&gt; input) {
    // ...
}


However, you can't use your arithmetic-based comparison, so you can change that to:

public static &lt;T extends Comparable&lt;T&gt;&gt; sort(Stack&lt;T&gt; input) {
    // ...
    if (fromUnsorted.compareTo(fromSorted) &gt;= 0) {
        // ...
    }
    // ...
}


And if you will like to make it even more 'generic' and cater for non-Comparable types, you can specify a Comparator&lt;T&gt; to do so:

public static &lt;T&gt; sort(Stack&lt;T&gt; input, Comparator&lt;T&gt; comparator) {
    // ...
    if (comparator.compare(fromUnsorted, fromSorted) &gt;= 0) {
        // ...
    }
    // ...
}