Results 1 to 2 of 2

Thread: ArrayList

  1. #1
    ramitmehra123 is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Default ArrayList

    I had a doubt concerning ArrayList

    If i want to add strings to an ArrayList is it required to have done a
    ArrayList prodSku = new ArrayList();

    or

    will it work fine with

    ArrayList prodSku

    at the end i want to do

    prodSku.add("abc");

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    // This is a declaration.
    // The reference "prodSku" is null, ie, does not
    // point to or refer to an object.
    ArrayList prodSku
    
    // This is a declaration and instantiation.
    // Now the reference "prodSku" points to an ArrayList.
    ArrayList prodSku = new ArrayList();
    
    // This is okay after "prodSku" has been
    // initialized to point/refer to an ArrayList.
    // Otherwise this line will generate a
    // NullPointerException at compile time.
    prodSku.add("abc");

Similar Threads

  1. Replies: 2
    Last Post: 04-21-2008, 11:43 AM
  2. ArrayList
    By kizilbas1 in forum New To Java
    Replies: 1
    Last Post: 01-12-2008, 08:48 PM
  3. ArrayList
    By kizilbas1 in forum New To Java
    Replies: 11
    Last Post: 12-05-2007, 07:30 PM
  4. New to arraylist
    By kleave in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 06:45 PM
  5. Help ArrayList.add()
    By eNine in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 01:13 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
  •