将集合转换为数组
import java.util.LinkedList; import java.util.List;/** 来 自 N o w J a v a . c o m**/ import java.util.Map; import java.util.Set; public class Main { public static void main(String[] argv) { List list = new LinkedList<>(); // Create an array containing the elements in a list Object[] objectArray = list.toArray(); MyClass[] array = (MyClass[]) list.toArray(new MyClass[list.size()]); Set set = null; // Create an array containing the elements in a set objectArray = set.toArray(); array = (MyClass[]) set.toArray(new MyClass[set.size()]); Map map = null; // Create an array containing the keys in a map/*n o w j a v a . c o m - 时 代 Java 提 供*/ objectArray = map.keySet().toArray(); array = (MyClass[]) map.keySet().toArray(new MyClass[set.size()]);