ZSort { String[] SortByZ(String[] g, int z) { HashMap<String, Integer> gp = new HashMap<>(); for (int i = 0; i < g.length; i++) { gp.put(g[i], i); } Comparator<String> comp = new Comparator<String>() { @Override public int compare(String s1, String s2) { char cz1 = Character.toLowerCase(s1.charAt(z - 1)); char cz2 = Character.toLowerCase(s2.charAt(z - 1)); int zc = Character.compare(cz1, cz2); if (zc != 0) { return zc; } return Integer.compare(gp.get(s1), gp.get(s2)); } }; Arrays.sort(g, comp); return g; }    }
@Test(dataProvider = "stringsResult") public void testIsomorphic(String[] strings, int z, String[] zSorted) { assertEquals(new ZSort().SortByZ(strings, z), zSorted); }