jdk1.5后版本才有的新特性以前都是都是Object类型的,取出来的时候要强制类型转换为自己想要的类型。现在这样就不用强制类型转换了在循环的时候也可以直接取出,提高效率,虽然你有肉眼是看不到。列如:List<String> strList = new ArrayList();strList.add("123"); strList.add("456");那么在循环的时候可以:for(String str:strList){ System.out.println("----------->>"+str); //可以直接取出 }提高类型转换与遍历的速度。
指定传入的类型。 LIST 里放的是INT型
List<Integer> list 一种泛型设计
Vector<String> x = new Vector<String>(); Vector<Integer> y = new Vector<Integer>(); boolean b = x.getClass() == y.getClass();同一个generic class的所有parameterized types在运行时共享同一个类 如以上b就为true
不想的话就理解为List中限定存放的数据类型
这样定义之后,这个list只能接收Integer的对象.
strList.add("456");那么在循环的时候可以:for(String str:strList){
System.out.println("----------->>"+str); //可以直接取出
}提高类型转换与遍历的速度。
Vector<Integer> y = new Vector<Integer>();
boolean b = x.getClass() == y.getClass();同一个generic class的所有parameterized types在运行时共享同一个类
如以上b就为true
我的理解是 <>里设置 这个集合里的元素 的类型
list 里的类型是 Integer