Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Compares two arrays of comparable elements lexicographically. * @param arr1 first array * @param arr2 second array * @param <T> comparable type of array elements * @return negative integer if {@code arr1} comes before {@code arr2}, * positive integer if {@code arr1} comes after {@code arr2}, * {@code 0} if arrays equal */ public static <T extends Comparable<T>> int compare(T[] arr1, T[] arr2) { int length = Math.min(arr1.length, arr2.length); for (int i = 0; i < length; i++) { int compare = arr1[i].compareTo(arr2[i]); if (compare != 0) return compare; } return arr1.length - arr2.length; } }