List list = new ArrayList();
String str = "hello";
list.add(str);
Integer integer =new Integer(1);
list.add(integer);
//取出list中的值
String str2 = (String)list.get(0);
System.out.println(str2);
System.out.println(list.size());
//iterator迭代器
List intList = new ArrayList();
for(int i=0;i<10;i++)
{
intList.add("i"+i);
}
Iterator it = intList.iterator();
while(it.hasNext()){
String inte = (String)it.next();
System.out.println(inte);
}
System.out.println("=================================for===========================================");
for(int j=0;j<intList.size();j++)
{
System.out.println(intList.get(j));
Collection collection = new ArrayList();
//向容器中加入對(duì)象
String str = "Hello";
collection.add(str);
Integer integer = new Integer(1);
collection.add(integer);
Object obj = new Object();
collection.add(obj);
//返回容器長度
//size返回collection中的元素?cái)?shù)
System.out.println("容器的長度:"+collection.size());
//如何取對(duì)象?
Object[] object = collection.toArray();
//未進(jìn)行類型轉(zhuǎn)換
System.out.println("第一個(gè)元素是:"+object[0]);
//移除容器中制定的對(duì)象
collection.remove(obj);
//清空容器中的對(duì)象
collection.clear();
System.out.println("容器的長度:"+collection.size());
聯(lián)系客服