Java List Reverse reverseUseList(int[] values)

Here you can find the source of reverseUseList(int[] values)

Description

reverse Use List

License

Apache License

Declaration

public static void reverseUseList(int[] values) 

Method Source Code

//package com.java2s;
/**/*from   w w  w  .j  a v a2  s.c  o m*/
 * HashMap?????????????????????????new??????????????????????????
 * ????????
 * code by guava-libraries.(Apache License 2.0)
 * https://code.google.com/p/guava-libraries/
 *
 * @return HashMap????????????????????????
 */

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class Main {

    public static void reverseUseList(int[] values) {
        List<Integer> list = new ArrayList<Integer>();
        for (int object : values) {
            list.add(object);
        }

        Collections.reverse(list);

        Integer[] integers = list.toArray(new Integer[0]);
        int i = 0;
        for (int value : integers) {
            values[i] = value;
            i++;
        }
    }

    public static void reverse(int[] values) {
        for (int i = 0; i < values.length / 2; i++) {
            int tmp = values[values.length - i - 1];
            values[values.length - i - 1] = values[i];
            values[i] = tmp;
        }
    }

    public static String reverse(String str) {
        char[] charArray = str.toCharArray();
        char[] resultChar = new char[charArray.length];
        for (int i = 0; i < charArray.length; i++) {
            resultChar[i] = charArray[charArray.length - i - 1];
        }
        String result = new String(resultChar);
        return result;
    }

    public static char[] toCharArray(String str) {
        char[] result = str.toCharArray();
        return result;
    }
}

Related

  1. reverseOrder(List list)
  2. reversePath(List pathParts)
  3. reversePermutation(final List permutation)
  4. reversePermutation(T[] arr, List p)
  5. reverseSort(final List lines)
  6. reverseVector(List vector)
  7. sortListBySublistSizeThenHead(List> list, boolean reverseOrder)
  8. sortReverse(List list)
  9. sortReverseOrder(List list)