This two-day project needs to use a sort, corresponding to 4 items, so write a comparator class.
The code is as follows:
import Java.util.Comparator;
/**
* www.webkkk.net
* @author WEBKKK
*
*/
public class Testcomparator implements Comparator {
public int Compare (object arg0, Object arg1) {
string[] strf = ((String) arg0). Split ("_");
String[] Strl = ((String) arg1). Split ("_");
int len = strf.length;
if (len = = 1) {
return Integer.parseint (strf[0])-Integer.parseint (strl[0]);
for (int i = 0; i < len; i++) {
if (!strf[i].equals (Strl[i])) {
return Integer.parseint (strf[i))-In Teger.parseint (Strl[i]);
} else {
String strnf = Getsubvalue (strf, i);
String STRNL = Getsubvalue (Strl, i);
Return Compare (STRNF, STRNL);
}
}
return 0;
}
public string Getsubvalue (string[] strobj, int npast) {
String strreturn = "";
for (int i = 1 + npast i < strobj.length i++) {
Strreturn = Strreturn + "_" + strobj[i];
return strreturn.substring (1);br>}
}