public static void main(String[] args) {Collection c = new ArrayList();// 添加元素c.add("hello");c.add("world");c.add("java");Object[] objs = c.toArray();for (int x = 0; x < objs.length; x++) {?//objs是Object[] 的對象名,但是Object類里面沒有length //方法,但在遍歷的時候為什么卻可以調用?//System.out.println(objs[x] + "---" + objs[x].length());? ?這里objs[x].length()就不可以,調用length為什么上面//就可以呢???String s = (String) objs[x];System.out.println(s + "---" + s.length());
初級。。集合框架,Object[]toArray,數組遍歷leng
冉冉說
2018-07-15 14:14:55