int (String @NotNull [] obj1, String @NotNull [] obj2) { for (int i = 0; i < Math.max(obj1.length, obj2.length); i++) { String o1 = i < obj1.length ? obj1[i] : null; String o2 = i < obj2.length ? obj2[i] : null; if (o1 == null) return -1; if (o2 == null) return 1; int res = o1.compareToIgnoreCase(o2); if (res != 0) return res; } return 0; }