Format Specifier for Hash Code in Java



Format specifier for Hash Code us %h.

Firstly, create a new object for Formatter and Calendar −

Formatter f = new Formatter();
Calendar c = Calendar.getInstance();

For hash code −

f.format("%h", c)

The following is an example that finds the hash code −

Example

 Live Demo

import java.util.Calendar;
import java.util.Formatter;
public class Demo {
   public static void main(String args[]) {
      Formatter f = new Formatter();
      Calendar c = Calendar.getInstance();
      System.out.println("Hash Code: "+f.format("%h", c));
   }
}

Output

Hash Code: 4b899958
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements