我该如何按列对此表进行排序?

时间:2014-03-02 01:24:22

标签: java sorting

https://www.mediafire.com/#myfiles

得到了这个程序,我不能按列对表进行排序,我使用冒泡排序但是表在排序后不会更新列表,只是将表用作临时存储而不是数据库。

感谢那些能帮助我的人。

 else if(e.getActionCommand().equals( "SORT" )) {
     String []list = new String[data.length];
     for (int row = 0; row < data.length; row++) {
        list[row] = (String) data[row][0];
     }
     for(int row=0;row<noOfStudents;row++){
         for(int column=0;column<noOfStudents;column++){
             if(list[column].compareTo(list[column+1])<0){
                 String a = list[column];
                 list[column]=list[column+1];
                 list[column+1]= a;
             }
         }
     }
     for(int row=0;row<noOfStudents;row++) {
            data[row][0]=list[row];
     }
     for(int row=0;row<noOfStudents;row++) {
            table.setValueAt(list[row], row, 0);
     }
 }

1 个答案:

答案 0 :(得分:0)

我还没有完全理解代码,但为什么你不使用:

 Arrays.sort(list);