Popular in Course
Popular in ComputerScienence
This 1 page Class Notes was uploaded by Betty Kertzmann on Monday September 21, 2015. The Class Notes belongs to CS 161 at Colorado State University taught by Elizabeth Boese in Fall. Since its upload, it has received 8 views. For similar materials see /class/210173/cs-161-colorado-state-university in ComputerScienence at Colorado State University.
Reviews for Object
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 09/21/15
Lecture Notes 6 ArrayLists Java has a nice class that creates a exible array of objects using shifting to make and cover holes to allow adding and removing elements When needed more space is allocated for a growing number of elements ArrayList is part of the javautil package ArrayLists dynamically grow and shrink and allow data elements to be inserted and deleted from any location index An ArrayList stores Objects which means that when you retrieve an element from an ArrayList you almost always need to cast it to its actual type How ArrayLists are actually implemented is not of concern to us All we care about is their interface The following list provides some but de nitely not all methods from the ArrayList interface 0 ArrayList Constructor creates an empty ArrayList o boolean isEmpty returns true if ArrayList empty false otherwise void clear empties the ArrayList int size returns the number of elements in the ArrayList boolean add Object 0 Adds 0 to the end of the ArrayLists Returns true void addint 1 Object 0 lnserts 0 at index i Shifts elements with now larger index to the right Object removeint i removes the indexed object and shifts elemnts with larger index left Object getint i retrieves the indexed object without removing it int indexOfObject 0 returns index of rst occurrence of o boolean c0ntainsObject 0 returns true if 0 occurs in the ArrayList false oth erwise We will demonstrate the use ArrayLists in the Travelling Salesman Problem