daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Playground {
  2.     public static void main(String[ ] args) {
  3.         String[] ex1 = new String[] { new String("a"), "b" };
  4.         String[] ex2 = new String[] { new String("a"), "b" };
  5.        
  6.         evaluateReferenceEquality(ex1, ex2);
  7.        
  8.         evaluateValueEquality(ex1, ex2);
  9.     }
  10.    
  11.     public static void evaluateReferenceEquality(String[] a, String[] b) {
  12.         System.out.println("Reference equality");
  13.        
  14.         for(int i = 0; i < a.length; i++) {
  15.             System.out.println(a[i] == b[i]);
  16.         }
  17.     }
  18.    
  19.     public static void evaluateValueEquality(String[] a, String[] b) {
  20.         System.out.println("Value equality");
  21.        
  22.         for(int i = 0; i < a.length; i++) {
  23.             System.out.println(a[i].equals(b[i]));
  24.         }
  25.     }
  26. }
  27.  
  28. /* Output:
  29. Reference equality
  30. false
  31. true
  32. Value equality
  33. true
  34. true
  35. */
RAW Paste Data
Top