Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array List Problem?

 
Avery Jerauld
Greenhorn
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avery Jerauld
Greenhorn
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic