java.util.ArrayList<E>
java.util.Arrays
java.util Interface Collection<E>
java.util Interface Iterator<E> 
java.util.Vector<E>
一直不是很明白他们的用法,只觉得有很多类似的方法,各位高手能详细讨论他们的联系和区别么?
尤其是在什么情况下使用他们?

解决方案 »

  1.   

    thinking in java,3rd
    11: Collections of Objects这一章讲得很详细,建议楼主看看
      

  2.   

    同意,呵呵
    也可以去看一下,Java的说明文档JavaTM 2 SDK, Standard Edition Documentation
    里面有他们之间的继承关系
      

  3.   

    To review the containers provided in the standard Java library: 
    1 An array associates numerical indices to objects. It holds objects of a known type so that you don’t have to cast the result when you’re looking up an object. It can be multidimensional, and it can hold primitives. However, its size cannot be changed once you create it. 2 A Collection holds single elements, and a Map holds associated pairs. 
     
    3 Like an array, a List also associates numerical indices to objects—you can think of arrays and Lists as ordered containers. The List automatically resizes itself as you add more elements. But a List can hold only Object references, so it won’t hold primitives, and you must always cast the result when you pull an Object reference out of a container. 4 Use an ArrayList if you’re doing a lot of random accesses, but a LinkedList if you will be doing a lot of insertions and removals in the middle of the list. 5 The behavior of queues, deques, and stacks is provided via the LinkedList. 6 A Map is a way to associate not numbers, but objects with other objects. The design of a HashMap is focused on rapid access, whereas a TreeMap keeps its keys in sorted order, and thus is not as fast as a HashMap. A  LinkedHashMap keeps its elements in insertion order, but may also reorder them with its LRU algorithm. 7 A Set only accepts one of each type of object. HashSets provide maximally fast lookups, whereas TreeSets keep the elements in sorted order. LinkedHashSets keep elements in insertion order.8 There’s no need to use the legacy classes Vector, Hashtable, and Stack in new code. The containers are tools that you can use on a day-to-day basis to make your programs simpler, more powerful, and more effective.
      

  4.   

    The Java 2 container library takes the issue of “holding your objects” and divides it into two distinct concepts: 
    1  Collection: a group of individual elements, often with some rule applied to them. A List must hold the elements in a particular sequence, and a Set cannot have any duplicate elements. (A bag, which is not implemented in the Java container library—since Lists provide you with enough of that functionality—has no such rules.) 2 Map: a group of key-value object pairs. At first glance, this might seem like it ought to be a Collection of pairs, but when you try to implement it that way the design gets awkward, so it’s clearer to make it a separate concept. On the other hand, it’s convenient to look at portions of a Map by creating a Collection to represent that portion. Thus, a Map can return a Set of its keys, a Collection of its values, or a Set of its pairs. Maps, like arrays, can easily be expanded to multiple dimensions without adding new concepts; you simply make a Map whose values are Maps (and the values of those Maps can be Maps, etc.). 中文版在这里 http://www.wgqqh.com/shhgs/tij.html 第11章!
      

  5.   

    The Java 2 container library takes the issue of “holding your objects” and divides it into two distinct concepts: 
    1  Collection: a group of individual elements, often with some rule applied to them. A List must hold the elements in a particular sequence, and a Set cannot have any duplicate elements. (A bag, which is not implemented in the Java container library—since Lists provide you with enough of that functionality—has no such rules.) 2 Map: a group of key-value object pairs. At first glance, this might seem like it ought to be a Collection of pairs, but when you try to implement it that way the design gets awkward, so it’s clearer to make it a separate concept. On the other hand, it’s convenient to look at portions of a Map by creating a Collection to represent that portion. Thus, a Map can return a Set of its keys, a Collection of its values, or a Set of its pairs. Maps, like arrays, can easily be expanded to multiple dimensions without adding new concepts; you simply make a Map whose values are Maps (and the values of those Maps can be Maps, etc.). 中文版在这里 http://www.wgqqh.com/shhgs/tij.html 第11章!