Swap the Values in a Generic Pair
mediumQuestion 176Complete 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, so print one after the last line.
Hints3 available
Sign in to use hintsTopics
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.