CUtils { public static Object[] map2Array(Map<?, ?> map){ Object[] array = new Object[map.size()*2]; int index = 0; for(Entry<?, ?> entry : map.entrySet()){ array[index++] = entry.getKey(); array[index++] = entry.getValue(); } return array; } private  CUtils(); static Collection<T> emptyIfNull(Collection<T> col); static List<T> emptyListIfNull(List<T> col); static Map<K, V> subtract(Map<K, V> first, Map<K, V> map); static Map<K, V> subtract(Map<K, V> first, Map<K, V> map, boolean modifyFirst); static Map arrayIntoMap(Class mapClass, Object... params); static Map<K, V> newMap(Class<? extends Map> clazz); static Map<K, V> asMap(Object... params); static Map<T, T> typeMap(T... params); static Map<String, Object> fromProperties(Object obj); static BaseMap toBase(Map map); static T arrayIntoMap(T properties, Object... params); static LinkedHashMap<K, V> asLinkedMap(Object...params); static List<T> newArrayList(); static List<T> newArrayList(int size); static List<T> newList(T...objs); static T[] newArray(T...objs); static HashSet<T> newHashSet(); static HashSet<T> asSet(T...objs); static HashSet<T> newHashSet(int size); static TreeSet<T> newTreeSet(); static Map<K, V> newMap(); static Map<K, V> newHashMap(int size); static CollectionMap<K, V> newListMap(int size); static LinkedHashMap<K, V> newLinkedHashMap(int size); static LinkedHashMap<K, V> newLinkedHashMap(); static List<T> trimAsList(T... array); static List<T> asList(T... array); static List tolist(Object object, boolean trimNull); static Collection<T> newCollections(Class<? extends Collection> clazz); static Collection<T> newCollections(Class<? extends Collection> clazz, Integer size); static Collection<T> toCollection(Object object); static List tolist(Object object, boolean trimNull, List def); static void appendToList(Object object, List list); static Collection stripNull(Collection collection); static List<T> trimAndexcludeTheClassElement(boolean trimNull, Object array, Object... excludeClasses); static Collection strip(Collection<?> collection, final Object... stripValue); static Object[] asArray(Object obj); static String[] asStringArray(Object obj); static Object[] map2Array(Map<?, ?> map); static Map<K, Collection<V>> groupBy(Collection<V> datas, ReturnableClosure<V, K> block); static void filter(Collection<T> collection, Predicate<T> predicate); static void filter(Map<K, V> map, Predicate<Entry<K, V>> predicate); static List<T> difference(List<T> list1, List<T> list2, NotInPredicate<T> notInPredicate); static List<T> difference(List<T> list1, List<T> list2, final String...properties); static boolean containsAnyOne(Collection<T> c, T...elements); static boolean contains(Collection<T> c, T element, EqualsPredicate<T> equalsPredicate); static boolean contains(Collection<T> c, T element, final String...properties); static boolean isEquals(T e1, T e2, EqualsPredicate<T> equalsPredicate); static boolean isEquals(final T e1, final T e2, final String...properties); static Map<Integer, Object> toMap(List<?> list); static Map<K, Object> toMap(List<?> list, IndexableReturnableClosure<Object, K> keyMap); static List<Object> toList(Map<?, ?> map); static List<R> map(Collection<T> list, Function<? super T, ? extends R> mapper); static List<T> iterableToList(Iterable<T> it); static Optional<Pair<Integer, T>> findByClass(List<?> list, Class<T> targetClass); static void replaceOrAdd(List list, Class targetClass, Object element); static void removeByClass(List<?> list, Class<?> targetClass); static NullOrEmtpyPredicate NullOrEmptyTrue; static NullOrEmtpyPredicate NullOrEmptyFalse; static final List NULL_LIST; }
@Test public void testMap2Array(){ Object[] values = new Object[]{"aa", "aavalue", "bb", 2L, "cc", new Object()}; Map<Object, Object> map = CUtils.asMap(values); Object[] array = CUtils.map2Array(map); Assert.assertEquals(values.length, array.length); for (int i = 0; i < array.length; i++) { Assert.assertEquals(values[i], array[i]); } }