This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt" Watch "Doubt" New topic
Author

Doubt

gangashri patil
Greenhorn

Joined: Sep 21, 2011
Posts: 3
what is difference between 1] List a=new List
2]ArrayList a=new ArrayList

which one is good to use?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to the Ranch.

java.util.List is an interface, so the first option is not going to work, because you can't instantiate an interface using new.

But probably you meant: List a = new ArrayList();

You're not the first one who asks this question, in fact, it is asked regularly on the forums here. It's the program to an interface, not an implementation principle.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: Doubt
 
Similar Threads
basic question about ArrayList
comparison of List & ArrayList
Object Creation
collection
Collections.copy method for lists ? how it works