Write a method called swapPairs that switches the order ofvalues in an ArrayList of strings in a pairwise fashion. Yourmethod should switch the order of the first two values, then switchthe order of the next two, then the next two, and so on. If thenumber of values in the list is odd, the method should not move thefinal element. For example, if the list initially stores [“to”,”be”, “or”, “not”, “to”, “be”, “hamlet”], your method should changethe list’s contents to [“be”, “to”, “not”, “or”, “be”, “to”,”hamlet”].
Solution
public void swapPairs(ArrayList<String> list) { String str; for(int
OR
OR