It is used to maintain lists of values in which the key is a String and the value is also a String. ("Hashtable contains 4 as value: " + ntains(4)) ("Hashtable contains 2 as value: " + ntains(2)) ("Initial table elements: " + hashtable) Then few entries are added, table is printed and using contains() we're checking about two values in the table. We've created a Hashtable object of Integer,Integer. The following example shows the usage of Java Hashtable contains() method to check if a value is present in a Hashtable or not. The specific meaning of keys with regard to hash tables is totally dependent on the usage of the hash table and the data it contains. The Hashtable class provides a means of organizing data based on some user-defined key structure.įor example, in an address list hash table you could store and sort data based on a key such as ZIP code rather than on a person's name. An enumeration is retrieved using keys() method and enumeration is then iterated to print the keys of the dictionary.Įnumeration enumeration = dictionary.keys() We're creating a dictionary instance using Hashtable object of Integer, Integer. The following example shows the usage of Java Dictionary keys() method. Since the Dictionary class is abstract, it provides only the framework for a key-mapped data structure rather than a specific implementation. This is useful in cases where you want to be able to access data via a particular key rather than an integer index. The Dictionary class is an abstract class that defines a data structure for mapping keys to values. The following program illustrates several of the methods supported by this data structure − This class is very useful in cases where you need to keep up with a set of Boolean values you just assign a bit to each value and set or clear it as appropriate. The BitSet class implements a group of bits or flags that can be set and cleared individually. To have more detail about this interface, check The Enumeration. Exampleįollowing is an example showing usage of Enumeration for a Vector. The Enumeration interface defines a means to retrieve successive elements from a data structure.įor example, Enumeration defines a method called nextElement that is used to get the next element in a data structure that contains multiple elements. The Enumeration interface isn't itself a data structure, but it is very important within the context of other data structures. These data structures consist of the following interface and classes −Īll these classes are now legacy and Java-2 has introduced a new framework called Collections Framework, which is discussed in the next chapter − The Enumeration The data structures provided by the Java utility package are very powerful and perform a wide range of functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |