Collection的使用
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
{
System.out.println(intList.get(j));
}
List的使用
Collection collection = new ArrayList();
//向容器中加入对象
String str = "Hello";
collection.add(str);
Integer integer = new Integer(1);
collection.add(integer);
Object obj = new Object();
collection.add(obj);
//返回容器长度
//size返回collection中的元素数
System.out.println("容器的长度:"+collection.size());
//如何取对象?
Object[] object = collection.toArray();
//未进行类型转换
System.out.println("第一个元素是:"+object[0]);
//移除容器中制定的对象
collection.remove(obj);
//清空容器中的对象
collection.clear();
System.out.println("容器的长度:"+collection.size());