Java DateFormat hashCode() Example

DateFormat class hashCode() method example. This example shows you how to use hashCode() method.


Syntax is : public int hashCode()
Method returns  hashCode of integer type.

Here is the code.
/**
 * @(#) HashCodeDateFormat.java
 * A class representing use of method hashCode() of DateFormat
class in java.text Package.
 * @Version  12-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class HashCodeDateFormat {

    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class    : " + date.toString());

        // Create new DateFormat object by getInstance method.
        DateFormat dateFormat = DateFormat.getInstance();
        String stringDate = dateFormat.format(date);
        System.out.println("Date by DateFormat class : " + stringDate);

        // hashCode method call.
        int hashCode = dateFormat.hashCode();
        System.out.println("Hash Code for this date format : " + hashCode);
    }
}
  

Output of the program.
 Date  by  Date  class    : Thu Jun 12 18:33:23 GMT+05:30 2008
Date by DateFormat class : 6/12/08 6:33 PM
Hash Code for this date format : -1455260666

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US