Write Method Called Swappairs Switches Order Values Arraylist Strings Pairwise Fashion Met Q37100870

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.