在 Java 中将 List<String> 转换为 String[]
2022-08-31 13:39:39
public static void main(String[] args) {
List<String> strlist = new ArrayList<String>();
strlist.add("sdfs1");
strlist.add("sdfs2");
String[] strarray = (String[]) strlist.toArray();
System.out.println(strarray);
}
错误:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
at test.main(test.java:10)