### Question:
NaturalOrderComparator implements Comparator<String> { @Override public int compare(String o1, String o2) { String a = o1.toString(); String b = o2.toString(); int ia = 0, ib = 0; int nza = 0, nzb = 0; char ca, cb; int result; while (true) { nza = nzb = 0; ca = charAt(a, ia); cb = charAt(b, ib); while (Character.isSpaceChar(ca) || ca == '0') { if (ca == '0') { nza++; } else { nza = 0; } ca = charAt(a, ++ia); } while (Character.isSpaceChar(cb) || cb == '0') { if (cb == '0') { nzb++; } else { nzb = 0; } cb = charAt(b, ++ib); } if (Character.isDigit(ca) && Character.isDigit(cb)) { if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) { return result; } } if (ca == 0 && cb == 0) { return nza - nzb; } if (ca < cb) { return -1; } else if (ca > cb) { return +1; } ++ia; ++ib; } }  @Override int compare(String o1, String o2);  }### Answer:
@Test public void compare() { List<String> strs = new ArrayList<>(); strs.add("shd_eleme_order_uid200"); strs.add("shd_eleme_order_uid100"); strs.add("shd_eleme_order_uida"); strs.add("shd_eleme_order_uid0"); strs.add("shd_eleme_order_uid1"); strs.add("shd_eleme_order_uid2"); strs.add("shd_eleme_order_uid3"); strs.add("shd_eleme_order_uid10"); strs.add("shd_eleme_order_uid11"); strs.add("shd_eleme_order_uid12"); strs.add("shd_eleme_order_uid20"); strs.add("shd_eleme_order_uid21"); strs.add("shd_eleme_order_uid22"); strs.sort(new NaturalOrderComparator()); List<String> result = new ArrayList<>(); result.add("shd_eleme_order_uid0"); result.add("shd_eleme_order_uid1"); result.add("shd_eleme_order_uid2"); result.add("shd_eleme_order_uid3"); result.add("shd_eleme_order_uid10"); result.add("shd_eleme_order_uid11"); result.add("shd_eleme_order_uid12"); result.add("shd_eleme_order_uid20"); result.add("shd_eleme_order_uid21"); result.add("shd_eleme_order_uid22"); result.add("shd_eleme_order_uid100"); result.add("shd_eleme_order_uid200"); result.add("shd_eleme_order_uida"); Assert.assertEquals(strs, result); }