Compare Java Arrays Online

Paste two Java arrays or collections (as JSON). See what was added, removed, or changed — element by element.

🔒 100% private — runs entirely in your browser

or try sample data

What is Java Array Compare?

Java Array Compare diffs two Java arrays or collections element by element. Java's == operator compares references, not values, and even Arrays.equals() only checks one level deep. This tool shows you a full visual diff with nested comparison.

Java has two kinds of array-like structures: primitive arrays (int[], String[]) and Collections (ArrayList, LinkedList). Both can be serialized to JSON for comparison. Whether you're debugging Spring Boot responses, comparing test fixtures, or reviewing Hibernate query results, visual diffs save time.

Serialize your data with Gson (new Gson().toJson(list)) or Jackson (mapper.writeValueAsString(list)) and paste it here. The tool handles nested objects, arrays, and mixed types.

Java Array Comparison — Code Examples

Arrays.equals — shallow comparison

import java.util.Arrays; String[] arr1 = {"spring", "hibernate", "junit"};
String[] arr2 = {"spring", "hibernate", "junit"}; System.out.println(Arrays.equals(arr1, arr2)); // true // But for nested arrays:
int[][] nested1 = {{1, 2}, {3, 4}};
int[][] nested2 = {{1, 2}, {3, 4}};
System.out.println(Arrays.equals(nested1, nested2)); // false!

Arrays.equals does not recurse into nested arrays. Use Arrays.deepEquals for that.

Arrays.deepEquals — recursive comparison

import java.util.Arrays; Object[][] arr1 = {{"a", 1}, {"b", 2}};
Object[][] arr2 = {{"a", 1}, {"b", 3}}; System.out.println(Arrays.deepEquals(arr1, arr2)); // false // Still only returns boolean — no detail on what changed

deepEquals tells you whether arrays are equal but not where the differences are.

Collection comparison with streams

import java.util.*;
import java.util.stream.*; List<String> list1 = List.of("spring", "hibernate", "junit", "maven");
List<String> list2 = List.of("spring", "quarkus", "junit", "gradle"); Set<String> set1 = new HashSet<>(list1);
Set<String> set2 = new HashSet<>(list2); Set<String> added = set2.stream() .filter(e -> !set1.contains(e)) .collect(Collectors.toSet());
// [quarkus, gradle]

Stream-based diffing works for flat collections but ignores index positions and nested objects.

Java Array Comparison Gotchas

== compares references, not values

In Java, arr1 == arr2 checks if both variables point to the same array object in memory. Even if two arrays contain identical elements, == returns false. Always use Arrays.equals() or Arrays.deepEquals().

Autoboxing changes equality behavior

Integer values between -128 and 127 are cached, so Integer.valueOf(127) == Integer.valueOf(127) is true. But Integer.valueOf(128) == Integer.valueOf(128) is false. This can cause unexpected results when comparing arrays of boxed integers.

ArrayList.equals vs Arrays.equals

ArrayList.equals() does element-by-element comparison using .equals(), which is correct. But Arrays.equals() on Object[] also uses .equals(), while == on arrays compares references. Know which comparison method your code is using.

Frequently Asked Questions

How do I compare two Java arrays online?

Serialize your arrays to JSON using Gson or Jackson and paste the JSON into the two panels. Click Compare to see element-by-element differences.

Why does == not work for Java arrays?

== in Java compares object references (memory addresses), not contents. Two arrays with identical elements are different objects, so == returns false. Use Arrays.equals() or Arrays.deepEquals().

Can this compare Java ArrayLists?

Yes. Serialize your ArrayList to JSON and paste it. JSON arrays map directly to Java Lists.

Is my data safe?

Yes. This tool runs entirely in your browser. No data is transmitted to any server.

Does this support Java records and POJOs?

Yes. Serialize records or POJOs to JSON with any Java JSON library. All fields will be compared recursively.

Can I ignore array order?

Yes. Check the "Ignore array order" option to compare arrays as unordered collections, similar to comparing Java Sets.