aspose file tools*
The moose likes Beginning Java and the fly likes Array List Problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array List Problem?" Watch "Array List Problem?" New topic
Author

Array List Problem?

Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

I am almost done with my online class. I'm failing it just barely. So I need to make sure I do good on these next two units. I was given the code:





But the
ArrayList<String> schools = new ArrayList<String>();

is apparently wrong. NetBeans says "cannot find symbol". The project is I need to execute this program and then build my own array list. I'm pretty sure I can do that myself (Just replace school with something and the names with something else, maybe add or take away some of the objects) but I don't even know what's wrong with that part since I've never done an array list before. Help?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

You need to import class java.util.ArrayList:

For extra points, note that it is better to program to an interface, not an implementation. This means you should write this:

instead of:

The rest of the program only needs to know that schools is a List, and not which particular implementation of List is being used (ArrayList in this case).

Note that if you do this, you ofcourse will also need to import java.util.List.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

Thanks! I wouldn't have thought it would have been such an easy solution. Just another import line.

And I'll definitely have to keep what you said in mind!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array List Problem?