3。   System.out.print(strMonths);//strMonths 是一个数组名称,相当于一个c++指针,所以输出不会正确。

解决方案 »

  1.   

    mix some of the One, Two,....Twelvel's cases. example: ONe, Two, thrEe, fOuR....and test again.{OR}change to this and test again. 
    static class Comp implements Comparator{
        public int compare(Object obj1,Object obj2){
    ---->      return !s1.compareTo(s2);
          }
       }
     In this case, leave your original array {"One", "Two", "Three"....}.
      

  2.   

    1. 用Arrays.sort(strMonths);后和用Arrays.sort(strMonths,new Comp());输出结果相同,两个方法到底有什么用?
    =======> The first method uses default comparator. The second one uses the provided comparator. If the two comparators are the same, the result should be the same also.
    2. 在类Comp()里面有个方法public int compare(Object obj1,Object obj2),有两个参数obj1,obj2,但调用改类时候并没有用到该方法而且并没有obj1,obj2的参数提供,(调用Comp()时根本没传入参数),为什么Arrays.sort(strMonths,new Comp());这样就能执行Comp()里面的方法?
    =======> sort will use the Comp's compare(o1,o2) automatically. If you put a System.out.println(...) there, you will see.
      

  3.   

    System.out.print(Object obj) or System.out.println(Object obj)
    will invoke obj.toString() method automatically and print the String to the console. strMonth is not a String, instead it's an Array. So, it prints the following [Ljava.lang.String;@45a877 indicating it's an array, String is its component Class type, 45a877 is its hash code. you can write your own method to convert an array to String.
        public static String arrayToString(Object array)
        {
            StringBuffer buf = new StringBuffer();        buf.append(array.toString() + "{");
            for (int i = 0; i < Array.getLength(array); i++)
                buf.append(Array.get(array, i) + ",");
            buf.append("}");        return buf.toString();
        }