Merge git+ssh://davetron5000@repo.or.cz/srv/git/vimdoclet
[vimdoclet.git] / sample / java.util.Hashtable.txt
blob6f52a909daa445f222a8780cf3391421349b8c25
1 *java.util.Hashtable* *Hashtable* This class implements a hashtable, which maps 
3 public class Hashtable
4   extends    |java.util.Dictionary|
5   implements |java.util.Map|
6              |java.lang.Cloneable|
7              |java.io.Serializable|
9 |java.util.Hashtable_Description|
10 |java.util.Hashtable_Fields|
11 |java.util.Hashtable_Constructors|
12 |java.util.Hashtable_Methods|
14 ================================================================================
16 *java.util.Hashtable_Constructors*
17 |java.util.Hashtable()|Constructs a new, empty hashtable with a default initial
18 |java.util.Hashtable(int)|Constructs a new, empty hashtable with the specified 
19 |java.util.Hashtable(int,float)|Constructs a new, empty hashtable with the spec
20 |java.util.Hashtable(Map)|Constructs a new hashtable with the same mappings as 
22 *java.util.Hashtable_Methods*
23 |java.util.Hashtable.clear()|Clears this hashtable so that it contains no keys.
24 |java.util.Hashtable.clone()|Creates a shallow copy of this hashtable.
25 |java.util.Hashtable.contains(Object)|Tests if some key maps into the specified
26 |java.util.Hashtable.containsKey(Object)|Tests if the specified object is a key
27 |java.util.Hashtable.containsValue(Object)|Returns true if this Hashtable maps 
28 |java.util.Hashtable.elements()|Returns an enumeration of the values in this ha
29 |java.util.Hashtable.entrySet()|Returns a Set view of the entries contained in 
30 |java.util.Hashtable.equals(Object)|Compares the specified Object with this Map
31 |java.util.Hashtable.get(Object)|Returns the value to which the specified key i
32 |java.util.Hashtable.hashCode()|Returns the hash code value for this Map as per
33 |java.util.Hashtable.isEmpty()|Tests if this hashtable maps no keys to values.
34 |java.util.Hashtable.keys()|Returns an enumeration of the keys in this hashtabl
35 |java.util.Hashtable.keySet()|Returns a Set view of the keys contained in this 
36 |java.util.Hashtable.put(K,V)|Maps the specified key to the specified   value i
37 |java.util.Hashtable.putAll(Map)|Copies all of the mappings from the specified 
38 |java.util.Hashtable.rehash()|Increases the capacity of and internally reorgani
39 |java.util.Hashtable.remove(Object)|Removes the key (and its corresponding valu
40 |java.util.Hashtable.size()|Returns the number of keys in this hashtable.
41 |java.util.Hashtable.toString()|Returns a string representation of this Hashtab
42 |java.util.Hashtable.values()|Returns a Collection view of the values contained
44 *java.util.Hashtable_Description*
46 This class implements a hashtable, which maps keys to values. Any non-null 
47 object can be used as a key or as a value. 
49 To successfully store and retrieve objects from a hashtable, the objects used 
50 as keys must implement the hashCode method and the equals method. 
52 An instance of Hashtable has two parameters that affect its performance: 
53 initial capacity and load factor. The capacity is the number of buckets in the 
54 hash table, and the initial capacity is simply the capacity at the time the 
55 hash table is created. Note that the hash table is open: in the case of a "hash 
56 collision", a single bucket stores multiple entries, which must be searched 
57 sequentially. The load factor is a measure of how full the hash table is 
58 allowed to get before its capacity is automatically increased. The initial 
59 capacity and load factor parameters are merely hints to the implementation. The 
60 exact details as to when and whether the rehash method is invoked are 
61 implementation-dependent. 
63 Generally, the default load factor (.75) offers a good tradeoff between time 
64 and space costs. Higher values decrease the space overhead but increase the 
65 time cost to look up an entry (which is reflected in most Hashtable operations, 
66 including get and put). 
68 The initial capacity controls a tradeoff between wasted space and the need for 
69 rehash operations, which are time-consuming. No rehash operations will ever 
70 occur if the initial capacity is greater than the maximum number of entries the 
71 Hashtable will contain divided by its load factor. However, setting the initial 
72 capacity too high can waste space. 
74 If many entries are to be made into a Hashtable, creating it with a 
75 sufficiently large capacity may allow the entries to be inserted more 
76 efficiently than letting it perform automatic rehashing as needed to grow the 
77 table. 
79 This example creates a hashtable of numbers. It uses the names of the numbers 
80 as keys: 
82 Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); 
83 numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); 
85 To retrieve a number, use the following code: 
87 Integer n = (Integer)numbers.get("two"); if (n != null) { 
88 System.out.println("two = " + n); } 
90 As of the Java 2 platform v1.2, this class has been retrofitted to implement 
91 Map, so that it becomes a part of Java's collection framework. Unlike the new 
92 collection implementations, Hashtable is synchronized. 
94 The Iterators returned by the iterator and listIterator methods of the 
95 Collections returned by all of Hashtable's "collection view methods" are 
96 fail-fast: if the Hashtable is structurally modified at any time after the 
97 Iterator is created, in any way except through the Iterator's own remove or add 
98 methods, the Iterator will throw a ConcurrentModificationException. Thus, in 
99 the face of concurrent modification, the Iterator fails quickly and cleanly, 
100 rather than risking arbitrary, non-deterministic behavior at an undetermined 
101 time in the future. The Enumerations returned by Hashtable's keys and values 
102 methods are not fail-fast. 
104 Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, 
105 generally speaking, impossible to make any hard guarantees in the presence of 
106 unsynchronized concurrent modification. Fail-fast iterators throw 
107 ConcurrentModificationException on a best-effort basis. Therefore, it would be 
108 wrong to write a program that depended on this exception for its correctness: 
109 the fail-fast behavior of iterators should be used only to detect bugs. 
111 This class is a member of the <a href="/../guide/collections/index.html"> Java 
112 Collections Framework. 
115 *java.util.Hashtable()*
117 public Hashtable()
119 Constructs a new, empty hashtable with a default initial capacity (11) and load 
120 factor, which is 0.75. 
123 *java.util.Hashtable(int)*
125 public Hashtable(int initialCapacity)
127 Constructs a new, empty hashtable with the specified initial capacity and 
128 default load factor, which is 0.75. 
130     initialCapacity - the initial capacity of the hashtable. 
132 *java.util.Hashtable(int,float)*
134 public Hashtable(
135   int initialCapacity,
136   float loadFactor)
138 Constructs a new, empty hashtable with the specified initial capacity and the 
139 specified load factor. 
141     initialCapacity - the initial capacity of the hashtable. 
142     loadFactor - the load factor of the hashtable. 
144 *java.util.Hashtable(Map)*
146 public Hashtable(java.util.Map t)
148 Constructs a new hashtable with the same mappings as the given Map. The 
149 hashtable is created with an initial capacity sufficient to hold the mappings 
150 in the given Map and a default load factor, which is 0.75. 
152     t - the map whose mappings are to be placed in this map. 
154 *java.util.Hashtable.clear()*
156 public synchronized void clear()
158 Clears this hashtable so that it contains no keys. 
161 *java.util.Hashtable.clone()*
163 public synchronized |java.lang.Object| clone()
165 Creates a shallow copy of this hashtable. All the structure of the hashtable 
166 itself is copied, but the keys and values are not cloned. This is a relatively 
167 expensive operation. 
170     Returns: a clone of the hashtable. 
171 *java.util.Hashtable.contains(Object)*
173 public synchronized boolean contains(java.lang.Object value)
175 Tests if some key maps into the specified value in this hashtable. This 
176 operation is more expensive than the containsKey method. 
178 Note that this method is identical in functionality to containsValue, (which is 
179 part of the Map interface in the collections framework). 
181     value - a value to search for. 
183     Returns: true if and only if some key maps to the value argument in this hashtable as 
184              determined by the equals method; false otherwise. 
185 *java.util.Hashtable.containsKey(Object)*
187 public synchronized boolean containsKey(java.lang.Object key)
189 Tests if the specified object is a key in this hashtable. 
191     key - possible key. 
193     Returns: true if and only if the specified object is a key in this hashtable, as 
194              determined by the equals method; false otherwise. 
195 *java.util.Hashtable.containsValue(Object)*
197 public boolean containsValue(java.lang.Object value)
199 Returns true if this Hashtable maps one or more keys to this value. 
201 Note that this method is identical in functionality to contains (which predates 
202 the Map interface). 
204     value - value whose presence in this Hashtable is to be tested. 
206     Returns: true if this map maps one or more keys to the specified value. 
207 *java.util.Hashtable.elements()*
209 public synchronized |java.util.Enumeration| elements()
211 Returns an enumeration of the values in this hashtable. Use the Enumeration 
212 methods on the returned object to fetch the elements sequentially. 
215     Returns: an enumeration of the values in this hashtable. 
216 *java.util.Hashtable.entrySet()*
218 public |java.util.Set| entrySet()
220 Returns a Set view of the entries contained in this Hashtable. Each element in 
221 this collection is a Map.Entry. The Set is backed by the Hashtable, so changes 
222 to the Hashtable are reflected in the Set, and vice-versa. The Set supports 
223 element removal (which removes the corresponding entry from the Hashtable), but 
224 not element addition. 
227     Returns: a set view of the mappings contained in this map. 
228 *java.util.Hashtable.equals(Object)*
230 public synchronized boolean equals(java.lang.Object o)
232 Compares the specified Object with this Map for equality, as per the definition 
233 in the Map interface. 
235     o - object to be compared for equality with this Hashtable 
237     Returns: true if the specified Object is equal to this Map. 
238 *java.util.Hashtable.get(Object)*
240 public synchronized |java.lang.Object| get(java.lang.Object key)
242 Returns the value to which the specified key is mapped in this hashtable. 
244     key - a key in the hashtable. 
246     Returns: the value to which the key is mapped in this hashtable; null if the key is not 
247              mapped to any value in this hashtable. 
248 *java.util.Hashtable.hashCode()*
250 public synchronized int hashCode()
252 Returns the hash code value for this Map as per the definition in the Map 
253 interface. 
256 *java.util.Hashtable.isEmpty()*
258 public synchronized boolean isEmpty()
260 Tests if this hashtable maps no keys to values. 
263     Returns: true if this hashtable maps no keys to values; false otherwise. 
264 *java.util.Hashtable.keys()*
266 public synchronized |java.util.Enumeration| keys()
268 Returns an enumeration of the keys in this hashtable. 
271     Returns: an enumeration of the keys in this hashtable. 
272 *java.util.Hashtable.keySet()*
274 public |java.util.Set| keySet()
276 Returns a Set view of the keys contained in this Hashtable. The Set is backed 
277 by the Hashtable, so changes to the Hashtable are reflected in the Set, and 
278 vice-versa. The Set supports element removal (which removes the corresponding 
279 entry from the Hashtable), but not element addition. 
282     Returns: a set view of the keys contained in this map. 
283 *java.util.Hashtable.put(K,V)*
285 public synchronized |java.lang.Object| put(
286   java.lang.Object key,
287   java.lang.Object value)
289 Maps the specified key to the specified value in this hashtable. Neither the 
290 key nor the value can be null. 
292 The value can be retrieved by calling the get method with a key that is equal 
293 to the original key. 
295     key - the hashtable key. 
296     value - the value. 
298     Returns: the previous value of the specified key in this hashtable, or null if it did 
299              not have one. 
300 *java.util.Hashtable.putAll(Map)*
302 public synchronized void putAll(java.util.Map t)
304 Copies all of the mappings from the specified Map to this Hashtable These 
305 mappings will replace any mappings that this Hashtable had for any of the keys 
306 currently in the specified Map. 
308     t - Mappings to be stored in this map. 
310 *java.util.Hashtable.rehash()*
312 protected void rehash()
314 Increases the capacity of and internally reorganizes this hashtable, in order 
315 to accommodate and access its entries more efficiently. This method is called 
316 automatically when the number of keys in the hashtable exceeds this hashtable's 
317 capacity and load factor. 
320 *java.util.Hashtable.remove(Object)*
322 public synchronized |java.lang.Object| remove(java.lang.Object key)
324 Removes the key (and its corresponding value) from this hashtable. This method 
325 does nothing if the key is not in the hashtable. 
327     key - the key that needs to be removed. 
329     Returns: the value to which the key had been mapped in this hashtable, or null if the 
330              key did not have a mapping. 
331 *java.util.Hashtable.size()*
333 public synchronized int size()
335 Returns the number of keys in this hashtable. 
338     Returns: the number of keys in this hashtable. 
339 *java.util.Hashtable.toString()*
341 public synchronized |java.lang.String| toString()
343 Returns a string representation of this Hashtable object in the form of a set 
344 of entries, enclosed in braces and separated by the ASCII characters "," (comma 
345 and space). Each entry is rendered as the key, an equals sign =, and the 
346 associated element, where the toString method is used to convert the key and 
347 element to strings. Overrides to toString method of Object. 
350     Returns: a string representation of this hashtable. 
351 *java.util.Hashtable.values()*
353 public |java.util.Collection| values()
355 Returns a Collection view of the values contained in this Hashtable. The 
356 Collection is backed by the Hashtable, so changes to the Hashtable are 
357 reflected in the Collection, and vice-versa. The Collection supports element 
358 removal (which removes the corresponding entry from the Hashtable), but not 
359 element addition. 
362     Returns: a collection view of the values contained in this map.