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.
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.
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
BentheMuffin
Nov 15, 9:10 AMCan 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);
}
Danail Dichev
Jan 24, 6:04 PM// getNote
public Note getNote(int pos){
Note gottenNote = notes.get(pos);
return gottenNote;
}
Bolke
Oct 8, 11:33 AMSo - 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.
Learneroo
Oct 8, 2:17 PMAs 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.
Bolke
Oct 9, 4:43 AMI 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.
Learneroo
Jun 16, 7:18 AMjava.lang.IndexOutOfBoundsException: Index: 0, Size: 0
means that it tried to access the first element in the ArrayList but the ArrayList was empty.