java - How to sort Strings considering the digits inside them? -


i have codes looking 1 of following:

  • aaa_bbb_d2_aa
    aaa_bbb_d3_aa
    aaa_bbb_d11_aa

  • eee_b2b_c2_ac

in general should sorted strings, in case of “aaa_bbb_d3_aa” vs. “aaa_bbb_d11_aa” former should come first in contrast simple string sorting.

the numerical part important sorting resides after either “_d” or “_c” substring , followed “_aa” or “_ac” ending string.

what efficient sorting algorithm in java or sql?

collections.sort(yourlistofstring, (string a, string b) -> {     int comparison = integer.valueof(a.split("_")[2].replaceall("[dc]", "")).compareto(integer.parseint(b.split("_")[2].replaceall("[dc]", "")));      return comparison == 0              ? a.split("_")[3].compareto(b.split("_")[3])              : comparison; }); 

(i assume strings in list)


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -