Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Objects.hashCode() API. It returns has code for the given objects.
package com.bethecoder.tutorials.guava.base_tests; import com.bethecoder.tutorials.guava.common.Student; import com.google.common.base.Objects; public class HashCodeTest { /** * @param args */ public static void main(String[] args) { Student student = new Student("Sriram", 2, "Chess"); Student student2 = new Student("Sudhakar", 29, "Painting"); int hashCode = Objects.hashCode(student, student2); //Internally uses Arrays.hashCode System.out.println("Hash code : " + hashCode); } }
Hash code : 300327489