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");
Printable View
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");
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");