ArrayList Methods and Docs


Premium Content - Free Preview

You've already seen ArrayList's add() method, but ArrayList comes with many other useful methods. You can read about it on the Learneroo ArrayList reference, but to get all the info you should lookup ArrayList on the Official Java 7 API Documentation. The documentation may seem confusing, but it's important to have some idea as to how to use it.

java-api-screenshot

Search
The first step to finding out more about a Library Class is to search for it. If you know the name of the Class, you can use Google, ctrl-F in your browser, or an extension to lookup the class on the official site.

Quick Documentation Lookup
Its useful to be quickly look up the documentation for a method while coding. To do this in BlueJ, press ctrl-space after starting to type the method name. You can also press it after typing the "dot" to pull up a list of all methods in that class. This will let you view documentation and select methods without having to type it all out manually. You can even use this shortcut for classes you create!
Here's an example of using ctrl-space to lookup String documentation:

Interface
As mentioned, you can use the Java Library without knowing how the Classes are implemented internally. All you need to know is its external interface:

  • A general description of what the class does
  • A list of its constructors and methods
  • The parameters taken in and the return type of each method and constructor
  • The purpose of each method and constructor

All of this information is provided in the official documentation.


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Comments

  • Can someone help me this code wont compile and I have no idea why.
    public String getNote(int p){
    String n = notes.get(p);
    return notes.get(p);
    }

  • // getNote
    public Note getNote(int pos){
    Note gottenNote = notes.get(pos);
    return gottenNote;
    }

  • So - there's no kind of feedback on the Tasks, right? Nor on whether they've been completed at all? I never do anything unless I have to, alas. That's why I come to this website to learn Java, instead of reading a book.

  • As mentioned in The String Class, you can download a provided BlueJ project and run test cases on your own computer after completing the code. This way you can get the benefit of coding in on your own computer and still get the feedback after completing your code.

  • I know. That's a very good thing. It's just, I'm the sort of person who never does that. I only complete something if, otherwise, you can't go on to the next page.
    Sad but true!

    Thanks for your answer.

  • java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 means that it tried to access the first element in the ArrayList but the ArrayList was empty.

Contact Us
Sign in or email us at [email protected]