<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.Arrays;
import java.util.List;
import java.util.Comparator;
import java.util.Collections;

public class OrdenarCorrecto {
   public static void main(String[] args) {
      List&lt;String&gt; strings = Arrays.asList("hola 1", "hola 5", "hola 15", "hola 2");
      Collections.sort(strings, new Comparator&lt;String&gt;() {
         public int compare(String o1, String o2) {
            return extractInt(o1) - extractInt(o2);
         }

         int extractInt(String s) {
            String num = s.replaceAll("\\D", "");
            return num.isEmpty() ? 0 : Integer.parseInt(num);
         }
      });
      System.out.println(strings);
   }
}

</pre></body></html>