9:18 am - Thursday February 23, 2017

Get HashCode of a given string int hashcode( )

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

This method returns a hash code for the given input.

Example Program

public class Hash 

  public static void main(String[] args)


  String s= “Srilekha";

  Integer i=15;

  Float f=12.0f;

  System.out.println("String value:" +s);

  System.out.println("Integer value:" +i);

  System.out.println("Float value:" +f);

  Integer hashcode=s.hashCode();

  Integer hash1=i.hashCode();

  Integer hash2=f.hashCode();

  System.out.println("Hash code for the string:" +hashcode);

  System.out.println("Hash code for integer value:" +hash1);

  System.out.println("Hash code for the float value:"+hash2);



   String value:Srilekha

   Integer value:15

   Float value:12.0

   Hash code for the string:-170509567

   Hash code for integer value:15

   Hash code for the float value:1094713344


          For the given input value, the output is generated in integer hash code and the generated value is stored in another variable.

Filed in: Java Examples

Comments are closed.