class ArrayList - Class ArrayList An instance of class...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Class ArrayList An instance of class java.util.ArrayList contains a list of objects. It may be a list of the courses you have taken, a list of high temperatures for each day in Ithaca in 2006, or a list of objects of totally different classes. There are methods for adding elements to the list, deleting elements, searching for an element, and so on. We il- lustrate these now, using DrJava as well as the powerpoint window so that you can see what is happening. Creating an ArrayList and appending elements to it First, let’s import class java.util.ArrayList and then create a new ArrayList —storing it in b . By calling function size of the new ArrayList object, you can see that it is initially empty. Let’s add a String object. As you can see, add is a function, which always returns true . The reason for this is beyond the scope of this course. Of course, you can always put a semicolon after the call to add and make a statement out of it, as we do here. If you give function add an integer as argument, autoboxing will
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

class ArrayList - Class ArrayList An instance of class...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online