日期:2014-05-20  浏览次数:20758 次

求解:Arrays类的反排序问题!
String[] a={"5","6","7","9","4","1","2"};
  int[] b={1,2,3,4,5,6};

  ??
for(int i=0 ;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
  ??
  for(int i=0 ;i<b.length;i++)
{
System.out.print(b[i]+" ");
}

如题:在问号行 要写上什么 才是反排序呢?谢谢!

------解决方案--------------------
手工写排序算法 或者装换成list
List asList = Arrays.asList(a);
Collections.reverse(asList);
asList.toArray();
------解决方案--------------------
看看Comparator与Comparable接口与Arrays,Collections,TreeSet,TreeMap之间的内在关联,明白了,玩对象排序杠杠的!!!