tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Basic > Multi Object Hashcode

Multi Object Hashcode 

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.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/HashCodeTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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);
  }

}
   

It gives the following output,
Hash code : 300327489



 
  


  
bl  br