CJCoding With Joseph
15per day

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

Expected Output:

right
left
2
1
Topics:
GenericsClasses
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.