The moose likes Beginning Java and the fly likes List list = new ArrayList() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "List list = new ArrayList()" Watch "List list = new ArrayList()" New topic

List list = new ArrayList()

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
I just learned that it is better to use List here in the place of the ArrayList. I would have private List horror = new ArrayList();
When I do this, I get a compiler error for the the last 2 lines of code.
After the List objects are instanstieated, they are filled with Strings and I want to get the size of the ArrayList after filling them.

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
What is the error?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You should always post a minimal, complete example program demonstrating your problem.
That way, forum members can simple copy, paste, compile and run your code.
As it is know, you didn't even tell us the error! We are left guessing!
And the few lines you posted, depending on where they occur in your code,
may or may not generate syntax errors. Again, learn to be a good forum
member and post short but complete code.

By the way, creating non-static fields like horror but copying its size
to a static field size_horror smells bad. That looks like a mistake in
the making...

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: List list = new ArrayList()
It's not a secret anymore!