Java examples for Collection Framework:Array Element
converse Array
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { Object[] arr = new String[] { "1", "abc", "level", null, "java2s.com", "asdf 123" }; System.out.println(java.util.Arrays.toString(converseArray(arr))); }/*from w ww . j a v a2 s . co m*/ public static Object[] converseArray(Object[] arr) { Object para = null; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static int[] converseArray(int[] arr) { int para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static char[] converseArray(char[] arr) { char para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static byte[] converseArray(byte[] arr) { byte para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static short[] converseArray(short[] arr) { short para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static long[] converseArray(long[] arr) { long para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static float[] converseArray(float[] arr) { float para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } public static double[] converseArray(double[] arr) { double para; for (int i = 0; i <= arr.length / 2; i++) { para = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = para; } return arr; } }