public class s086 { public static void main(String[] args) 
        {
          for( Object obj: get() ){System.out.println(obj+"..");}
}

public static Collection get(){
Collection sorted = new LinkedList();
sorted.add("B");
sorted.add("C");
sorted.add("A");
return sorted;

}
}

解决方案 »

  1.   

    输出是:
    B..
    C..
    A..
      

  2.   

    为什么是BCA  不排序的?
      

  3.   

    LinkedList 是不排序的,按照添加的顺序保存!
      

  4.   

    你可以用TreeSet 来代替
      public static void main(String[] args) {
        for (Object obj : get()) {
          System.out.println(obj + "..");
        }
      }  public static Collection get() {
        Collection sorted = new TreeSet();
        sorted.add("B");
        sorted.add("C");
        sorted.add("A");
        return sorted;
      }
      

  5.   

    对,LinkedList是按照添加顺序的。
      

  6.   

    LinkedList是按照添加顺序的。
      

  7.   

    在return前加上:Collections.sort((List)sorted); 就可以排序了。