Description
Program to get hash code for Boolean object. We are using hashCode() method of Boolean class for this purpose, it returns integer 1231 if this object represents true; returns the integer 1237 if this object represents false.
Example
class BooleanHashCodeEx { public static void main(String[] args) { // Boolean objects Boolean bObj, bObj2; // Assigning values to both the objects bObj = new Boolean(true); bObj2 = new Boolean(false); // integers to store hash code int icode, icode2; // Getting Hash Code icode = bObj.hashCode(); icode2 = bObj2.hashCode(); // Displaying HashCode for both the objects System.out.println("Hash code of "+bObj+" is "+icode); System.out.println("Hash code of "+bObj2+" is "+icode2); } }
Output:
Hash code of true is 1231 Hash code of false is 1237
public int hashCode()
: Returns a hash code for this Boolean object. It returns the integer 1231 if this object represents true; returns the integer 1237 if this object represents false.
Leave a Reply