Java Utililty Methods Array Reverse

List of utility methods to do Array Reverse

Description

The list of methods to do Array Reverse are organized into topic(s).

Method

T[]reverse(T[] array)
Reverses the elements of an array (inplace!)
for (int i = 0; i < array.length / 2; i++) {
    T s = array[i];
    array[i] = array[array.length - 1 - i];
    array[array.length - 1 - i] = s;
return array;
T[]reverse(T[] originalArray)
reverse
T[] array = Arrays.copyOf(originalArray, originalArray.length);
int indexA = 0, indexB = array.length - 1;
T temp;
while (indexB > indexA) {
    temp = array[indexB];
    array[indexB] = array[indexA];
    array[indexA] = temp;
    indexA++;
...
IterablereverseArray(final T[] arr)
Reverses the given array for iteration.
return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            private int pos = arr.length;
            @Override
            public boolean hasNext() {
                return pos > 0;
...
Object[]reverseArray(Object[] arr)
reverse Array
List<Object> list = Arrays.asList(arr);
Collections.reverse(list);
return list.toArray();
T[]reverseArray(T[] arr)
Utility function to reverse an array of any type.
List<T> list = Arrays.asList(arr);
Collections.reverse(list);
return (T[]) list.toArray();
ArrayListreverseArrayList(ArrayList listIn)
This will simply reverse an ArrayList
ArrayList reversed = (ArrayList) listIn.clone();
Collections.reverse(reversed);
return reversed;
ArrayListreverseList(ArrayList l)
reverse List
if (l == null)
    return null;
Iterator i = l.iterator();
ArrayList<Object> result = new ArrayList<Object>();
while (i.hasNext()) {
    result.add(0, i.next());
return result;
...
voidreverseRange(final T[] arr, final int from, final int to)
Reverses the order of a range of the array in place.
final int mid = (to - from) / 2 + from;
for (int i = from; i < mid; ++i) {
    swap(arr, i, to - i - 1);
SortedSetreverseSortedSet(int[] ints)
reverse Sorted Set
TreeSet sortedSet = new TreeSet(Collections.reverseOrder());
for (int i = 0; i < ints.length; i++) {
    sortedSet.add(new Integer(ints[i]));
return sortedSet;
voidsortReversed(final int[] a)
Sorts the specified int array in reversed order.
if (a.length <= 1)
    return; 
Arrays.sort(a);
final int last = a.length - 1;
for (int i = last / 2; i >= 0; i--) {
    final int temp = a[i];
    a[i] = a[last - i];
    a[last - i] = temp;
...