I study a tutorial about JAVA and this was an example of it about collections.However when i try to call method sort,the system can not find it.Why?I have imported java.util.*
The error occurs at this line Collections.sort(l);//sort the listpackage collections; import java.util.*;//library public class Collections { //Purpose:Create an ArrayList which stores strings public static void main(String[] args) { List<String> l = new ArrayList(); String first="Hello"; l.add(first); l.add(" world"); l.add("JAVA"); l.set(2,"JAVA2");//set modifies a value of the list Collections.sort(l);//sort the list System.out.println(l); System.out.println("Size of the list = " + l.size()); int i = l.indexOf(" world");//will return the position of <world> System.out.println("String <world> is at " + i + " cell"); l.remove("JAVA2");//will remove the first appearence of <JAVA2> l.clear();//removes all the elements of the list if(l.isEmpty()) System.out.println("empty list"); System.out.println(l); } }