Here you can find the source of arrayAsList(Object value)
Parameter | Description |
---|---|
value | something that might be an array |
null
otherwise
@SuppressWarnings({ "unchecked", "rawtypes" }) public static List<Object> arrayAsList(Object value)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { /**//ww w .j a v a 2 s . co m * Transforms any array to a matching list * * @param value * something that might be an array * @return List representation if passed in value was an array, * <code>null</code> otherwise */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static List<Object> arrayAsList(Object value) { List list = null; if (value instanceof int[]) { list = new ArrayList(); int[] array = (int[]) value; for (int i : array) { list.add(i); } } else if (value instanceof short[]) { list = new ArrayList(); short[] array = (short[]) value; for (short i : array) { list.add(i); } } else if (value instanceof char[]) { list = new ArrayList(); char[] array = (char[]) value; for (char i : array) { list.add(i); } } else if (value instanceof byte[]) { list = new ArrayList(); byte[] array = (byte[]) value; for (byte i : array) { list.add(i); } } else if (value instanceof long[]) { list = new ArrayList(); long[] array = (long[]) value; for (long i : array) { list.add(i); } } else if (value instanceof double[]) { list = new ArrayList(); double[] array = (double[]) value; for (double i : array) { list.add(i); } } else if (value instanceof float[]) { list = new ArrayList(); float[] array = (float[]) value; for (float i : array) { list.add(i); } } else if (value instanceof boolean[]) { list = new ArrayList(); boolean[] array = (boolean[]) value; for (boolean i : array) { list.add(i); } } else if (value.getClass().isArray()) { Object[] array = (Object[]) value; list = Arrays.asList(array); } return list; } }