package com.slliver.util;
import com.slliver.test2.Employee;
import java.util.ArrayList;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 2017/4/25 0025
* Time: 下午 20:34
* To change this template use File | Settings | File Templates.
*/
public class CollectionsUtil {
public static void main(String[] args) {
List employeeList = new ArrayList(3);
Employee e1 = new Employee("tom1", 22);
Employee e2 = new Employee("tom2", 22);
Employee e3 = new Employee("tom3", 22);
employeeList.add(e1);
employeeList.add(e2);
employeeList.add(e3);
Employee[] employees = new Employee[employeeList.size()];
employees = employeeList.toArray(employees);
for (Employee e : employees) {
System.out.println(e.getName());
}
}
}
建议使用 toArray(T[] t) 这种方式。