Question: Write a method that swaps the first and last elements in an ArrayList of Strings. For example, if we had an ArrayList list with the

Write a method that swaps the first and last elements in an ArrayList of Strings.
For example, if we had an ArrayList list with the values [hello,world]:
swapFirstLast(list)
Should return an ArrayList with the elements:
["world", "hello"]
If we had an ArrayList list with the values [hello]:
swapFirstLast(list)
Should return an array with the elements:
["hello"]
swapFirstLast(new ArrayList())
Should return an empty ArrayList:
[]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!