list - Alphabetizing in Java- error and warnings? -


i'm trying create program alphabetizes list, using collections.sort method , java.util.list, error is: 1 error , 15 warnings found:

error: java.util.list abstract; cannot instantiated -------------- ** warnings ** -------------- warning: unchecked call add(e) member of raw type java.util.list warning: unchecked method invocation: method sort in class java.util.collections applied given types   required: java.util.list<t>   found: java.util.list 

my code:

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 

just error said, list abstract, need concrete implementation. in case posted, arraylist do.

also note using list raw type; don't (unless using version before java 5). parameterize type parameter (here, string).

yet also: don't change declaration of words arraylist: list enough (normally), , left unchanged, gain ability change implementation later on.

in conclusion:

list<string> words= new arraylist<string>(); 

or if using java 7:

list<string> words= new arraylist<>(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -