Here you can find the source of toArray(T arrayOrCollection)
public static <T> Object[] toArray(T arrayOrCollection)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { public static <T> Object[] toArray(T arrayOrCollection) { if (arrayOrCollection instanceof Collection) { return ((Collection) arrayOrCollection).toArray(); } else {/*from w ww. ja v a2s . c o m*/ return (Object[]) arrayOrCollection; } } }