File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes what is wrong with this Arraylist expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is wrong with this Arraylist expression" Watch "what is wrong with this Arraylist expression" New topic
Author

what is wrong with this Arraylist expression

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124



The above code generates an error .. why ??
i know that Collection is an interface and List is also an interface which inherits from Collection and Arraylist is an implimentation of List then why the error??
even the site http://www.javamex.com/tutorials/collections/using_1.shtml
is using it this way ... am i missing anything ??


Don’t look where you fall, but where you slipped
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4421
    
    8

Is that exactly how the code appears? Because an import statement needs to be at the beginning of the file, and the other line needs to be within a class.

Otherwise, it would be helpful if you gave the error message.
Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

The code is



I am using eclipse SE ..
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Adam Zedan wrote:The code is



I am using eclipse SE ..

Hi, dont use java.awt.List this List is different from the List in Collections framework.
You have already imported complete java.util package which contains java.util.List and java.util.ArrayList


Piyush
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4421
    
    8

Piyush is right. It's trying to use the wrong List.

If you do need java.awt.List in that file, then you can get round it by using the fully qualified name:
Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

Worked...thanks.. Removed the otehr import statement.. Thanks for clearing that up
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Beware of imports in IDEs. If you write L-i-s-ctrl-space in Eclipse®, it will expand it to anything beginning with Lis, including java.awt.List and java.util.List. It displays the options in alphabetical order, so awt comes before util, and you can very easily pick the wrong List.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is wrong with this Arraylist expression