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

Equivalences 

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 Equivalences.equals() and Equivalences.identity() API.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/EquevalenceTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.base_tests;

import com.google.common.base.Equivalences;

public class EquevalenceTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    String str1 = new String("BTC");
    String str2 = new String("BTC");
    String str3 = str1;
    
    System.out.println(Equivalences.equals().equivalent(str1, str2));
    System.out.println(Equivalences.equals().equivalent(str1, str3));
    System.out.println(Equivalences.equals().equivalent(str2, str3));
    
    System.out.println(Equivalences.identity().equivalent(str1, str2));
    System.out.println(Equivalences.identity().equivalent(str1, str3));
    System.out.println(Equivalences.identity().equivalent(str2, str3));
    
    System.out.println(Equivalences.equals().equivalent(null, null));
    System.out.println(Equivalences.identity().equivalent(null, null));
  }

}
   

It gives the following output,
true
true
true

false
true
false

true
true



 
  


  
bl  br