

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
How to use java's arraylist class to store and manage quiz scores. The basics of arraylists, including their properties, methods, and how they differ from arrays. The document also includes an explanation of indexing and parameterized types or generics in the context of arraylists. A lecture note for csis 110 students using java 1.5.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Quiz Results (Before EC) mean 19. stdev 3. median 18. max 25 Distribution (after EC): <15: 1 15-17: 4 17.5 – 19.5: 3 20 – 22: 3 22.5 – 24.5: 1 25+: 6 Last time: this, debugger Chapter 4 - Collections A couple of comments:
These classes are stored the Java Library , and are organized into packages. Each package contains many classes. Let’s look at the Java documentation. We are going to look at one of these many classes: ArrayList Note: The book was written using Java 1.4. We are using Java 1.5, and there are some differences. One of these difference has to do with how collections work. This means that the code in the book is NOT identical to the code we will be discussing. Look at Notebook project (notebook1) Note that when you compile the Notebook, you get an error message. Ignore it for now, we’ll get back to this shortly. The first statement is used to tell Java that we are using a class from the Library. If we leave this line out, Java doesn’t know where to look for the ArrayList class. The import statements come before the class declaration. Once we have imported a class, we can use it just as if it was a class we had written ourselves. We can create objects of that type and call methods on those objects. private ArrayList notes; This statement declares a variable named notes that is an ArrayList. Because ArrayList is a class, we need to create an object of this type. notes = new ArrayList(); Once we have an ArrayList object, we can use its methods. Although ArrayList has many methods, we are only going to look at 3 of them: add, get, and size. add – store an object in the list size – return the number of objects in the list get – get an object from the list (but don’t remove it) Let’s look at how an ArrayList might work. See figures 4.1 and 4.2 (page 83) Properties of ArrayLists: Variable size – an ArrayList gets bigger if necessary as we add more items It keeps track of the number of items it currently contains It maintains the order of the items. We can retrieve the items in the same order as we added them.