aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 13884
    
  10

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
 
 
subject: Doubt
 
Similar Threads
Object Creation
comparison of List & ArrayList
Collections.copy method for lists ? how it works
collection
basic question about ArrayList