请看下面的代码,在while遍历里,为什么还要做String s = (String)it.next()呢,我存的本来就是字符串啊,怎么还要强转呢???
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add("abc356");
al.add("abc3543");
al.add("abc126");
al.add("abc0897");
Iterator it = al.iterator();
while (it.hasNext())
{
String s = (String)it.next();
System.out.println(s+"...."+s.length());
}
} |