package com.day15.collection;
import java.util.ArrayList;
import java.util.Collection;
public class Array_toArray {
public static void main(String[] args) {
Collection c=new ArrayList();
c.add(1);//支持自动装箱,事实上将1转换成了字符串对象
c.add("k");
c.add("o");
Object[] arr=c.toArray();//将元素转成数组
for (int i = 0; i < arr.length; i++) {
if(i==arr.length-1) {System.out.println(arr[i]);}//o
else {System.out.print(arr[i]+",");}//1,k,
}
}
}
//最后输出1,k,o
原文地址:https://www.cnblogs.com/zhujialei123/p/8998796.html
时间: 2024-10-21 12:46:49