我试图创建一个按字母顺序排列的列表中的程序,使用Collections.sort方法和java.util.List中,错误的是:1个错误和警告15发现:Java中的alphabetizing-错误和警告?
Error: java.util.List is abstract; cannot be instantiated
--------------
** Warnings **
--------------
Warning: unchecked call to add(E) as a member of the raw type java.util.List
Warning: unchecked method invocation: method sort in class java.util.Collections is applied to given types
required: java.util.List<T>
found: java.util.List
我的代码:
public static void preset(){
List words= new List();
words.add("apple");
words.add("country");
words.add("couch");
words.add("shoe");
words.add("school");
words.add("computer");
words.add("yesterday");
words.add("wowza");
words.add("happy");
words.add("tomorrow");
words.add("today");
words.add("research");
words.add("project");
Collections.sort(words);
} //end of method preset
感谢的作品也,我怎么打印此新排序列表?我试图打印它通过调用主要的方法,但这是行不通的 – user2399999
你可以发布它是如何不工作? System.out.println(文字)应该足够了。 –