How to swap the first and last elements of an ArrayList ? I know how to exchange array elements: setting a temporary value to store the first element, letting the first element equal the last element, and then letting the last element equal the stored first element.
int a = values[0]; int n = values.length; values[0] = values[n-1]; values[n-1] = a;
So, for an ArrayList<String> would that be?
String a = words.get(0); int n = words.size(); words.get(0) = words.get(n-1); words.get(n-1) = a
java arraylist
qvd Apr 12 '13 at 5:12 2013-04-12 05:12
source share