Just after exiting the swap method: After the statements: x = iPair.getFirst(); y = iPair.getSecond(); Notice that x and y have been swapped!