Java SimpleDateFormat hashCode() Example

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


Syntax is : public int hashCode()
This method returns the hash code value for this SimpleDateFormat object.

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

class HashCodeSimpleDateFormat {

    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());
        SimpleDateFormat sdf;

        // Create new SimpleDateFormat object that returns default pattern.
        sdf = new SimpleDateFormat();
        String dateFormat = sdf.format(date);
        System.out.println("Date by SimpleDateFormat class : " + dateFormat);

        // hashCode method call for SimpleDateFormat object.
        int hashCode = sdf.hashCode();
        System.out.println("Hash code of simple date format :" + hashCode);

    }
}

Output of the program.
Date  by  Date  class          : Sat Jun 14 13:08:26 GMT+05:30 2008
Date by SimpleDateFormat class : 6/14/08 1:08 PM
Hash code of simple date format :-1455260666

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

HOME | COPYRIGHT | CONTACT US