In this section, you will learn how to associate value with an object in Java util.
Associate a value with an object
In this section, you will learn how to associate value with an object in Java util. Here, you will know how to associate the value for the separate code. Values regarding to the separate code are maintained as a record of the specific person.
This program associates a value with an object. It takes four numeric value for the hash code of the several separate object and takes four other other string value to assign for the particular object which is treated as a record of the specific object by maintaining has map.
Here the multiple methods and APIs had been used by the program.
This class is used to making map interface to the hash table for comparing the object key and object values. It creates a new and empty identity hash map with default size. It gets maximum default size up to 21. For using out of the default range you have to specify that.
put(Object object_name, Object object_value):
Above method helps you to associate values for the specific object in the IdentityHashMap. It takes the object name of the object and it's value.
This is the interface extends the Collection class. It does not contain duplicate items. Set implements all the general Collection methods but it ensures that no any element store twice in the set.
Above method returns the view of the set record in the created map.
Iterators process all the elements of the Collection. This is the interface which is implemented for every Collections differently.
This program has also used generics which is given below:
JDK 1.5 provides one of the several extentions to the java programming language i.e. the "generics". This allows you to abstract over types. Here, in this program the code given in the program
IdentityHashMap<Integer,String> map = new IdentityHashMap<Integer,String>();
determines the new version of the program fragment of old
typed program using "generics".
In this code, IdentityHashMap is a generic class that takes type parameters for identifying the retrieved value whether it is false or true. This program uses the put() method of the IdentityHashMap class which puts the two types values one is the integer value and another is the string type value. So, this program firs store the passed type parameter with the IdentityHashMap class and its constructor i.e. the <Integer, String>.
Here is the code of program: