读书笔记

1,java中为什么使用容器或者什么情况下使用容器(Think in java)

In general, your programs will always be creating new objects based on some criteria that will be known only at the time the program is running. You won’t know until run time the quantity or even the exact type of the objects you need. To solve the general programming problem, you need to be able to create any number of objects, anytime, anywhere. So you can’t rely on creating a named reference to hold each one of your object

since you’ll never know how many of these you’ll actually need.

Most languages provide some way to solve this rather essential problem. Java has several ways to hold objects (or rather, references to objects). The built-in type is the array, which has been discussed before. Also, the Java utilities library has a reasonably complete set of container classes

2,ArrayList 是怎么通过Array实现的

 create an array object, its size is fixed and cannot be changed for the lifetime of that array object.You might suggest creating an array of a particular size and then,  if you run out of space, creating a new one and moving all the references from the old one to the new one. This is the behavior of the ArrayList class

3,集合里不能有原生数据类型

You need to build only one container, and any Java object will go into that container. (Except for primitives, which can be placed in containers as constants using the Java primitive wrapper classes, or as changeable values by wrapping in your own class.) This is the second place where an array is superior to the generic containers: When you create an array, you create it to hold a specific type (which is related to the third factor—an array can hold primitives, whereas a container cannot).

posted @ 2013-06-20 11:19  Little_cheeper  阅读(169)  评论(0编辑  收藏  举报