This should make it seamless:
public static final
T t = a[i];
a[i] = a[j];
a[j] = t;
}
public static final
Collections.
}
private void test() {
String [] a = {“Hello”, “Goodbye”};
swap(a, 0, 1);
System.out.println(“a:”+Arrays.toString(a));
List
swap(l, 0, 1);
System.out.println(“l:”+l);
}
Nope. You could have a function to make it more concise each place you use it, but in the end, the work done would be the same (plus the overhead of the function call, until/unless HotSpot moved it inline — to help it with that, make the functon static final).