日期:2014-05-20 浏览次数:20691 次
import java.util.List; /** * Created by IntelliJ IDEA. * User: admin * Date: 2011-10-12 * Time: 10:55:57 * To change this template use File | Settings | File Templates. */ public class TransferStrAry { public static void main(String[] args) { Object[] os={"a","b","c"}; // List list=o. for(Object o:os){ System.out.println("out:"+o); } } }
------解决方案--------------------
你的object[]是怎么得来的
如果类似将list转成String[],即list.toArray(new String[0]);
------解决方案--------------------
应该这样调用
import java.util.List; import java.util.ArrayList; public class TransferStrAry { public static void main(String[] args) { List list = new ArrayList(); list.add("asdfasdf"); list.add("sfh"); list.add("345"); String[] str =new String[list.size()]; list.toArray(str); for(String s:str){ System.out.println(s); } } }
------解决方案--------------------
String[] str=list.toArray(new String[0]);
------解决方案--------------------
List list = new ArrayList(); list.add("asdfasdf"); list.add("sfh"); list.add("345"); String[] str = (String[]) list.toArray(new String[0]); System.out.println(str.length);