From what I see you just try to see if they are equal, if this is true, just go with something like this:

boolean areEqual = Arrays.equals(arr1, arr2);

This is the standard way of doing it.

Please note that the arrays must be also sorted to be considered equal, from the JavaDoc:

Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements in the same order.

Sorry for missing that.

Answer from comanitza on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-arrays-compare-method-with-examples
Java Arrays compare() Method with Examples - GeeksforGeeks
Example of Arrays.compare() method, where we compare two integer arrays with the same elements. ... import java.util.Arrays; public class ArrayCompare { public static void main(String[] args) { // Initialize two integer array with same elements int[] arr1 = { 1, 2, 3, 4 }; int[] arr2 = { 1, 2, 3, 4 }; // compare arr1 and arr2 using compare() method // and print the result System.out.println( "" + Arrays.compare(arr1, arr2)); } }
Published: April 14, 2026
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ compare
Java Array compare()
While Java does not have a built-in compare() method specifically for arrays, it provides utility methods in the java.util.Arrays class to facilitate array comparison.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java array โ€บ comparing arrays in java
Comparing Arrays in Java | Baeldung
January 8, 2024 - We compare strings by using the compareTo method of type String. We want to be able to find if arrays are equal regardless of the sorting order. To do that, letโ€™s now sort our arrays: Arrays.sort(planes1[0], planeComparator); Arrays.sort(...
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 9 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ Arrays.html
Arrays (Java SE 9 & JDK 9 )
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2) must not throw a ...
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-arrays-compare-method-explained-7989daf18608
Javaโ€™s Arrays.compare() Method Explained | Medium
February 6, 2025 - The compare() method in the java.util.Arrays class provides a way to compare two arrays lexicographically. This means it determines which array is greater, smaller, or if they are equal by checking the elements in order.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ compare-two-arrays-java
Compare Two Arrays in Java - GeeksforGeeks
July 23, 2025 - Java provides a direct method Arrays.equals() to compare two arrays.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @codeforhunger โ€บ how-to-compare-arrays-in-java-with-examples-93e96ed08ca8
How to Compare Arrays in Java with Examples | by CodeForHunger | Medium
September 3, 2024 - import java.util.Arrays; public class ComparingArrays { public static void main(String[] args) { int arr1[] = {1,2,3,4,5}; int arr2[] = {6,7,8,9,10}; //comparing array contents if(Arrays.equals(arr1,arr2)) System.out.println("Given two arrays are the same"); else System.out.println("Given arrays are not the same"); } }
๐ŸŒ
CodeJava
codejava.net โ€บ java-core โ€บ collections โ€บ comparing-arrays-in-java-examples
Comparing Arrays in Java Examples
April 11, 2024 - [Master REST API Development and Java and Spring Boot] Besides sorting, searching, copying and filling, the java.util.Arrays class also provides convenient methods for comparing two arrays and returning hash code an array.
๐ŸŒ
DEV Community
dev.to โ€บ aurban28 โ€บ arraysmismatch-and-arrayscompare-in-java-15ch
mismatch() and compare() in Java - DEV Community
November 30, 2024 - When working with arrays in Java, the Arrays class offers several methods to manipulate and compare arrays. Two such methods are mismatch and compare, both of which deal with array comparison but serve different purposes.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-how-to-handle-array-comparisons-efficiently-418518
How to handle array comparisons efficiently | LabEx
Array comparison is a fundamental operation in Java programming that allows developers to compare the contents, order, and equality of arrays.
๐ŸŒ
Oracle
blogs.oracle.com โ€บ javamagazine โ€บ java-quiz-arrays-compare-mismatch
Quiz yourself: Comparing Java arrays and interpreting the mismatch method | javamagazine
July 10, 2023 - That leads to the documentation for Integer.compare(int, int) which states ยท Compares two int values numerically. The value returned is identical to what would be returned by: Integer.valueOf(x).compareTo(Integer.valueOf(y))
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-compare-two-arrays-in-java
How to compare two arrays in Java
Following example uses equals method to check whether two arrays are or not. import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { int[] ary = {1,2,3,4,5,6}; int[] ary1 = {1,2,3,4,5,6}; int[] ary2 = {1,2,3,4}; System.out.println("Is array 1 equal to array 2??
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-arrays-equals-method-explained-271f9420177d
Javaโ€™s Arrays.equals() Method Explained | Medium
September 11, 2024 - The Arrays.equals() method in Java is an important tool when working with arrays, allowing developers to compare two arrays for equality. If youโ€™re dealing with primitive types or objects, Arrays.equals() makes sure that each element is evaluated ...
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ equals
Java Array equals()
The Arrays.equals() method in Java is a utility function provided by the java.util.Arrays class. It is used to compare two arrays for equality. This method checks whether two arrays are equal by comparing the elements in both arrays in sequence.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-how-to-compare-two-long-arrays-in-java-413956
How to compare two long arrays in Java | LabEx
Versatility: Arrays can store a wide range of data types, from primitive types to complex objects, making them a versatile data structure. Compatibility with Java libraries: Many Java libraries and methods are designed to work seamlessly with ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java โ€บ util โ€บ arrays_compare_char.htm
Java Arrays compare() Method
... The Java Arrays compare(char[] a, int aFromIndex, int aToIndex, char[] b, int bFromIndex, int bToIndex) method compares the two arrays of chars in the given ranges lexicographically.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ java, comparing objects from an array
r/learnprogramming on Reddit: Java, comparing objects from an array
May 2, 2022 -

Hello, I'm currently learning java by creating a project, it's going to be a poker game.

I have a card class, each card has its suit and rank, there are 4 suits and 12 ranks.
I created 2 arrays, 1 is responsible for holding all cards of decks and the other one holds players cards (currently it's 1 v 1 game, so this array holds 4 cards only).

I put cards in first array by: deck.add(new Card(i,x), where 'i' is 0-3, and 'x' is 0-12, then I randomize order of that array by shuffle method and then put first 4 cards of first array to second array.
Right now I wanna compare 2 cards by ranks and later by suits. I have getters in cards class but I don't know how to use it for arrays.
When I create cards this way:
Card a = new Card(3,11);
Card b = new Card(2,1);
I can use a.getRank and b.getRank and compare them, but I don't know how I can use it for cards created in loop directly to array, because I can't use getRank. Could you please give me a hint? Thank you.