Format Specifier for Hash Code in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 21-Dec-2018 11:38:41
Advertisements