โ Back to Classes
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
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.