CJCoding With Joseph
15free / daySign inCreate account

Swap the Values in a Generic Pair

Complete the swap() method in the Pair<T> class so it exchanges the values of first and second.

The full class is provided. Only fill in the body of swap().

IMPORTANT: Do NOT write a main method. A hidden test will create String and Integer pairs, call swap(), then print the swapped values using getFirst() and getSecond().

Expected Output:

right
left
2
1

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
GenericsClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.