http://www.csdn.net/Expert/topicview.asp?id=690270
解决方案 »
- Swing Jtree如何实现这样显示
- 读取字符时乱码
- 用java怎么做出类似Dreamweaver那种效果
- 一个文件被转换成base64编码的字符串后,又用utf-8的编码形式写入到一个xml文件里,如果由xml文件里面的字符串还原为原来的文件?
- 求助:jbuilder9正式版的crack文件,(好象KeyGen.exe不顶用啊?~~)
- 非常感谢发来的树
- 为什么我的JAVA程序编译通过了,但却不能执行?
- 用Java实现Server-Client结构的聊天系统
- 关于网站搜索技术的讨论?
- 求教一个比较初级的java编译问题
- 有什么办法自己用java编写一个数据库读写的文件呀?
- 你知道吗?是java阵营的就看过来!
int array[] = new int[2];
array[1]=20;
array[2]=10;
Arrays.sort(array);
应该是:
int array[] = new int[2];
array[0]=20;
array[1]=10;
Arrays.sort(array);
/////!!!!
另外如果要满足你的要求,那就自己来排序好了!
private Integer _indexes[] = null;
private Object _needSort[] = null;
private int _indexes;
private boolean _ascending;
然后定义:
public void reallocateIndexes()
{
_indexes = new Integer[_needSort.length];
// Initialise with the identity mapping.
for (int r = 0; r < _indexes; r++)
{
_indexes[r] = new Integer(r);
}
}对它进行排序:
public void sortByColumn(final boolean ascending)
{
try
{
_ascending = ascending;
//we must reallocate here,
//if we use old value, we may not sort correctly.
reallocateIndexes();
java.util.List list = Arrays.asList(_indexes);
Collections.sort(list, new Comparator(){ public int compare(Object r1,Object r2)
{
try
{
// get the real object that we want to sort.
// i.e. we do not sort by r1 or r2.
// but compair o1 and o2.
int i1 = ((Integer)r1).intValue();
int i2 = ((Integer)r2).intValue();
Object o1 = _needSort[i1]
Object o2 = _needSort[i2]
// If both values are null, return 0.
if (o1 == null && o2 == null)
{
return 0;
}
else if (o1 == null)
{
// Define null less than everything.
return _ascending ? -1 : 1;
}
else if (o2 == null)
{
return _ascending ? 1 : -1;
}
// if can not compare o1 and o1, change the type of them
if(!(o1 instanceof Comparable) || !(o2 instanceof Comparable))
{
o1 = o1.toString();
o2 = o2.toString();
}
int gt = ((Comparable)o1).compareTo(o2);
return _ascending ? gt : (-1)*gt;
}
catch(Exception e)
{
ErrorLog.OutputLog(e);
return 0;
}
}
});
//After sort, we get this result.
//That is result what we need
_indexes = (Integer[])list.toArray();
}
catch(Exception e)
{
ErrorLog.OutputLog(e);
}
}