Comparing Arrays in JAVA JAVA by Ravinder Nath Rajotiya - April 17, 2021April 17, 20210 Comparing Arrays When we create array objects, they are created in memory at some memory address. Each array that is created is assigned different address. So, when we compare the array objects with == operators, their memory location get compared. So, they will never be equal even when they have the same values assigned to them. Same is the case when we compared string objects. Wrong way of comparing / Common mistake / Never compare arrays with == package com.example; public class arrays { public static void main(String[] args) { int []numbers1 ={2,4,6,8,10}; int []numbers2 ={2,4,6,8,10}; if (numbers1 == numbers2) { System.out.println("they are the same"); } else { System.out.println("they are not the same"); } } } So, we cannot compare the two array objects with == operators, because that will compare the memory