Difference

Hi friends,

can any one say what is the different between 2 declaration ?

List<String> words =new ArrayList<String>();

and

ArrayList<String> words =new ArrayList<String>();

Thanks

[308 byte] By [MCA134a] at [2007-11-27 3:49:30]
# 1
The first is declared as a List. The second as an ArrayList.
prometheuzza at 2007-7-12 8:53:23 > top of Java-index,Java Essentials,Java Programming...
# 2
meaning with the first declaration, you won't be able to call the methods defined in arraylist without casting (except for overriden methods), i think
calvino_inda at 2007-7-12 8:53:23 > top of Java-index,Java Essentials,Java Programming...
# 3

> meaning with the first declaration, you won't be able

> to call the methods defined in arraylist without

> casting (except for overriden methods), i think

correct. Also meaning, your program doesn't care whether it's an ArrayList or LinkedList or any other list, which is very useful if you later have to change the implementation because a LinkedList is more appropriate than an ArrayList or whatever.

CeciNEstPasUnProgrammeura at 2007-7-12 8:53:23 > top of Java-index,Java Essentials,Java Programming...
# 4

>List<String> words = new ArrayList<String>();

Here u can use all methods of List only....

>ArrayList<String> words = new ArrayList<String>();

Here u can enjoy methods of List as well as ArrayList....

I hopet his will be clear......

Thanks

SUSHANT_Ja at 2007-7-12 8:53:23 > top of Java-index,Java Essentials,Java Programming...