public class SwapTester { public static void swap3(Integer x, Integer y) { int t = x.intValue(); x.setInt(y.intValue()); y.setInt(t); } public static void swap2(Integer x, Integer y) { Integer t = x; x = y; y = t; } public static void swap(int x, int y) { System.out.println( "before" + x + ", " + y); int t = x; x = y; y = t; System.out.println( "after" + x + ", " + y); } public static void main(String[] args) { Integer ia = 1; Integer ib = 2; System.out.println( ia + ", " + ib); swap(ia, ib); System.out.println( ia + ", " + ib); // int a = 1; // int b = 2; // System.out.println( a + ", " + b); // swap(a, b); // System.out.println( a + ", " + b); } }