9.java.util Package

1
java.util.Collection
  |
  +--Set           ,     List
      |                   |
      +--SortedSet        + (Vector)
java.util.Map
  |
  +--SortedMap , (Hashtable)
interfaces effectively.
Collection:
  The Collection interface is the root of the collection hierarchy. A Collection represents a group of objects, known as its elements. Some Collection implementations allow duplicate elements and others do not. Some are ordered and others unordered. The JDK doesn't provide any direct implementations of this interface: It provides implementations of more specific subinterfaces like Set and List. This interface is the least common denominator that all collections implement. Collection is used to pass collections around and manipulate them when maximum generality is desired.
Set:
   A Set is an UNORDERED collection that CANNOT contain duplicate elements. As you might expect, this interface models the mathematical set abstraction. It is used to represent sets like the cards comprising a poker hand, the courses making up a student's schedule, or the processes running on a machine.
List:
 A List is an ORDERED collection (sometimes called a sequence). Lists CAN contain duplicate elements. The user of a List generally has precise control over where in the List each element is inserted. The user can access elements by their integer index (position). If you've used Vector, you're already familiar with the general flavor of List. (Note that, Vector implements List, hence Collection. and not Set.)
Map:
 A Map is an object that maps keys to values. Maps cannot contain duplicate keys: Each key can map to at most one value. If you've used Hashtable, you're already familiar with the general flavor of Map. (Note that, Hashtable implements Map). (Key and value cannot be null, otherwise a NullPointerException is thrown).
  The last two core collection interfaces (SortedSet and SortedMap) are merely sorted versions of Set and Map. In order to understand these interfaces, you have to know how order is maintained among objects.
  Object Ordering
There are two ways to order objects: The Comparable interface provides automatic natural order on classes that implement it, while the Comparator interface gives the programmer complete control over object ordering. Note that these are not core collection interfaces, but underlying infrastructure.
SortedSet:
   A SortedSet is a Set that maintains its elements in ascending order. Several additional operations are provided to take advantage of the ordering. The SortedSet interface is used for things like word lists and membership rolls.
SortedMap:
   A SortedMap is a Map that maintains its mappings in ascending key order. It is the Map analogue of SortedSet. The SortedMap interface is used for apps like dictionaries and telephone directories.

2.製表說明各自的isPrority ,isDuplicate value, has key, isNull
.

hasDupisOrder
hasNullKey
hasNullValisSynch
Collections(i)
YN
/

 
List(i)Y
Y
/

 
ArrayList





-LinkList

Y



-Vector(c)


/
N
Y
Set(i)NN
/

 
-HashSet(c)N
N
/
Y

--LinkHashSet(C)
N
Y(add)
/


-SortSet(i)

Y
/


--TreeSet(c)N
Y
/
N

Map(i)
N
N
N


-HashMap(c)

Y
Y

-SortMap(i)

Y
N


--TreeMap(c)




Dictionary(c)





-Hashtable(c)
 Y
N
N
Y

3.
Of all the collection classes of the java.util package, only Vector and HashTable are Thread-safe. The Collection class contains a synchronizedCollection() method that creates thread-safe instances based on collections which are not.
For example:
Set s = Collections.synchronizedSet(new HashSet(...));

AVI
1.java.util.Arrays:
   排序sort(A)
   自定義的類如果要排序,可以實現接口Comparable,並override     compareTo(Object o)方法,
   必須排序後纔可以用 binarySearch(A,key) 查詢 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章