Results 1 to 2 of 2

Thread: Java lists

  1. #1
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Java lists

    Hello,

    I am looking at the List<> in java and after googling around I couldnt find definte answers to my questions.
    I had thought that you would declare as:

    Java Code:
    List<Object> item = new List<Object> ();
    but that doenst work, so I have it figured out 2 ways, can someone explain which is better and why? Or another option...

    Java Code:
    List<Object> item = null;
    List<Object> item2 = new ArrayList<Object>();
    Thanks

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The one which sets the value to null is just not yet initialized. You can have the type be of List, but you can't instantiate an instance of list. It's an interface(might be an abstract class, either way you can't instantiate either)

    You must instead instantiate some implementing class, arraylist, linkedlist etc.

Similar Threads

  1. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 04:14 AM
  2. Help with lists
    By datreta in forum New To Java
    Replies: 6
    Last Post: 10-29-2010, 12:33 PM
  3. Deleting and Adding Lists in Java Applets
    By Bomber_Will in forum Java Applets
    Replies: 4
    Last Post: 11-28-2008, 07:52 AM
  4. comparision between two lists
    By suprabha in forum Advanced Java
    Replies: 14
    Last Post: 08-01-2008, 03:49 PM
  5. Java Collection Framework (Lists)
    By Java Tutorial in forum Java Tutorial
    Replies: 1
    Last Post: 05-16-2008, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •