arraylist向下转型为数组

2024-12-04 19:31:44
推荐回答(2个)
回答(1):

Iterator it = arraylist1.iterator();
while(it.hasNext){
String[] s = (String[])it.next();
}

如果当时你申明了类型:
ArrayList arraylist1 = ...

for(String[] s :arraylist1){
System.out.print(s.length);//s即是保存的String数组
}

回答(2):

for(int i=0; ilong[] ls = (long[])arraylist1.get(i);
long l1 = ls[0];
long l2 = ls[1];
System.out.println("l1=" + l1 + " l2=" + l2);
}

for(int i=0; iString[] s = (String[])arraylist2.get(i);
String s1 = s[0];
String s2 = s[1];
System.out.println("s1=" + s1 + " s2=" + s2);
}