← Back to Generics
Question 176
Swap the Values in a Generic Pair
Swap the Values in a Generic Pair
Complete theswap()method in thePair<T>class so it exchanges the values offirstandsecond. The full class is provided. Only fill in the body ofswap(). IMPORTANT: Do NOT write a main method. A hidden test will create String and Integer pairs, callswap(), then print the swapped values usinggetFirst()andgetSecond().
Expected Output:
right left 2 1
= newline. The output ends with a newline — 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.