十一 20
由于集合类(Collection)里面只能保存从Object当中继承而来的对象,所以对于基本类型(Primitive Type)的变量,如int,float等,在添加到Collection当中时,需要使用他们对应的封装类Integer,Float等,如:
ArrayList
list.add(0, new Integer(42));
int total = (list.get(0)).intValue();
在5.0当中,通过使用Autoboxing和Auto-Unboxing我们就不再需要显式的使用这些封装类了。
ArrayList
list.add(0, 42);
int total = list.get(0);
Tags: j2se
Leave a Reply
You must be logged in to post a comment.
近期评论