Thursday, October 2, 2008

it was sort problem of arrays

how to sort arrays with multiple elements of them?

I have a problem with sort of arrays.

for example

problem
//code start
...
public static void main(String [] args){
//case 1
//chkBoxPre, chkboxPost, code1, code2
String a1 = {"1","0","42","12"};
String a2 = {"0","1","32","23",};
List a = new ArrayList();
a.add(a1);
a.add(a2);

TestBean tb01 = new TestBean();
TestBean tb02 = new TestBean();
List b = new ArrayList();
b.add(tb01 );
b.add(tb02 );
}
...

public class TestBean implements Comparable, Serializable{
...
public int compareTo(Object arg0) {
TestBean tb = (TestBean) arg0;
//play with compareTo
if(tb.chkBoxPre.compareTo(this.chkBoxPre)==-1){
return 1;
}else{
return -1;
}
}
}
//code ends

current status
1. it's impossible to sort arrays in a list.

solution
1. so make the array to class shaped like bean.
1.1 the bean implements comparable
1.2 and implements compareTo