@Override public int compare(final String string1,final String string2){
  String string1Copy=string1.toLowerCase();
  String string2Copy=string2.toLowerCase();
  int len1=string1.length();
  int len2=string2.length();
  String liczba1="";
  String liczba2="";
  for (int i=0; i < ((len1 > len2) ? len1 : len2); i++) {
    if (i == len1 && len2 > len1) {
      return -1;
    }
    if (i == len2 && len1 > len2) {
      return 1;
    }
    Character c1=string1Copy.charAt(i);
    Character c2=string2Copy.charAt(i);
    if (isDigit(c1) && isDigit(c2)) {
      liczba1+=c1;
      liczba2+=c2;
    }
 else     if (isDigit(c1) && liczba1.length() > 0) {
      return 1;
    }
 else     if (isDigit(c2) && liczba1.length() > 0) {
      return -1;
    }
 else {
      if (!liczba1.equals(liczba2)) {
        return liczba1.compareTo(liczba2);
      }
      liczba1="";
      liczba2="";
      if (!c1.equals(c2)) {
        return c1.compareTo(c2);
      }
    }
  }
  return string1Copy.compareTo(string2Copy);
}

@ Override public int compare ( final String string1 , final String string2 ) { String string1Copy = string1 . toLowerCase ( ) ; String string2Copy = string2 . toLowerCase ( ) ; int len1 = string1 . length ( ) ; int len2 = string2 . length ( ) ; String liczba1 = "" ; String liczba2 = "" ; for ( int i = 0 ; i < ( ( len1 > len2 ) ? len1 : len2 ) ; i ++ ) { if ( i == len1 && len2 > len1 ) { return - 1 ; } if ( i == len2 && len1 > len2 ) { return 1 ; } Character c1 = string1Copy . charAt ( i ) ; Character c2 = string2Copy . charAt ( i ) ; if ( isDigit ( c1 ) && isDigit ( c2 ) ) { liczba1 += c1 ; liczba2 += c2 ; } else if ( isDigit ( c1 ) && liczba1 . length ( ) > 0 ) { return 1 ; } else if ( isDigit ( c2 ) && liczba1 . length ( ) > 0 ) { return - 1 ; } else { if ( ! liczba1 . equals ( liczba2 ) ) { return liczba1 . compareTo ( liczba2 ) ; } liczba1 = "" ; liczba2 = "" ; if ( ! c1 . equals ( c2 ) ) { return c1 . compareTo ( c2 ) ; } } } return string1Copy . compareTo ( string2Copy ) ; }
comapres two string in natural sort order .
