Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Playground {
- public static void main(String[ ] args) {
- String[] ex1 = new String[] { new String("a"), "b" };
- String[] ex2 = new String[] { new String("a"), "b" };
- evaluateReferenceEquality(ex1, ex2);
- evaluateValueEquality(ex1, ex2);
- }
- public static void evaluateReferenceEquality(String[] a, String[] b) {
- System.out.println("Reference equality");
- for(int i = 0; i < a.length; i++) {
- System.out.println(a[i] == b[i]);
- }
- }
- public static void evaluateValueEquality(String[] a, String[] b) {
- System.out.println("Value equality");
- for(int i = 0; i < a.length; i++) {
- System.out.println(a[i].equals(b[i]));
- }
- }
- }
- /* Output:
- Reference equality
- false
- true
- Value equality
- true
- true
- */
Add Comment
Please, Sign In to add comment