1168 Java Utilities (Submit web site) Package and Bit Manipulation Chapter

1168 Java Utilities Package and Bit Manipulation Chapter 20 Lines 59 60 call Hashtable method put to add a key (the first argument) and a value (the second argument) into the Hashtable. Method putreturns null if key has not been inserted in the Hashtablepreviously. Otherwise, method putreturns the original value for that key in the Hashtable; this helps the program manage cases in which it intends to replace the value stored for a given key. If either the key or the value is null, a NullPointerExceptionoccurs. Line 88 calls Hashtable method get to locate the value associated with the key specified as an argument. If the key is present in the table, getreturns an Objectreference to the corresponding value; otherwise, the method returns null. Lines 116 117 call Hashtable method remove to remove a key value pair from the table. The method returns a reference to the removed Object. If there is no value mapped to the specified key, the method returns null. Line 144 calls Hashtable method isEmpty, which returns true if the Hash- tableis empty; otherwise it returns false. Line 162 calls Hashtable method containsKey to determine whether the key specified as an argument is in the Hashtable(i.e., a value is associated with that key). If so, the method returns true; otherwise, the method returns false. Class Hashtable also provides method contains to determine whether the Objectspecified as its argument is in the Hashtable. Line 179 calls Hashtablemethod clear to empty the Hashtablecontents. Line 199 calls Hashtable method elements to obtain an Enumerationof the values in the Hashtable. Line 223 calls Hashtablemethod keys to obtain an Enumeration of the keys in the Hashtable. For more information on class Hashtableand its methods, see the online Java API documentation. 20.6 PropertiesClass A Properties object is a persistent Hashtableobject that normally stores key value pairs of Strings assuming that you use methods setProperty and getProperty to manipulate the table rather than Hashtablemethods putand get. By persistent, we mean that the Hashtableobject can be written to an output stream and directed to a file, and read back in through an input stream. In fact, most objects in Java can now be output and input with Java s object serialization (see Chapter 16). The Properties class extends class Hashtable, so Properties objects have the methods we discussed in Fig. 20.3. The keys and values in a Propertiesobject must be of type String. Class Propertiesprovides some additional methods that are demonstrated in Fig. 20.4. 1 // Fig. 20.4: PropertiesTest.java 2 // Demonstrates class Properties of the java.util package. 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.io.*; 8 import java.util.*; Fig. 20.4 Demonstrating class Properties(part 1 of 6).
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services

Leave a Reply