SNU IDB Lab. Ch5. Linear Lists – Array Representation © copyright 2006 SNU IDB Lab.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Chapter 23 Organizing list implementations. This chapter discusses n The notion of an iterator. n The standard Java library interface Collection, and.
Chapter 21 Implementing lists: array implementation.
Linear Lists – Array Representation
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
List Representation - Chain Fall 2010 CSE, POSTECH.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
Abstract Data Types data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
CHAPTER 3 COLLECTIONS SET Collection. 2 Abstract Data Types A data type consists of a set of values or elements, called its domain, and a set of operators.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
Vectors. Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: –Arrays have special syntax; Vector s don’t.
Data Structures data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
Arrays And ArrayLists - S. Kelly-Bootle
Chapter 3 Introduction to Collections – Stacks Modified
Announcements  I will discuss the labtest and the written test #2 common mistakes, solution, etc. in the next class  not today as I am still waiting.
04/29/ Introduction to Vectors?... A vector is a dynamic array. - It can be expanded and shrunk as required - A Component of a vector can be accessed.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
ArrayList, Multidimensional Arrays
Lists Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Linear List Array representation Data structures A data structure is a particular way of storing and manipulating data in a computer so that it can be.
Chapter 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Data Structure Specification  Language independent  Abstract Data Type  C++  Abstract Class.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
SNU IDB Lab. Ch6. Linear Lists – Linked Representation © copyright 2006 SNU IDB Lab.
1 Lecture 8 b Data Structures b Abstraction b The “Structures” package b Preconditions and postconditions b Interfaces b Polymorphism b Vector class b.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:
Linear (or Ordered) Lists instances are of the form (e 0, e 1, e 2, …, e n-1 ) where e i denotes a list element n >= 0 is finite list size is n.
-TAs and office hours announced
The Class ArrayLinearList
Abstract Data Types data object set or collection of instances
List Representation - Array
Data Representation Methods
Data Representation Methods
TCSS 143, Autumn 2004 Lecture Notes
Lecture 2: Implementing ArrayIntList reading:
Data Representation Methods
Programming in Java Lecture 11: ArrayList
بردارها و ماتريس ها ساختمان داده ها
-TAs and office hours announced
CSE 143 Lecture 27: Advanced List Implementation
Lecture 26: Advanced List Implementation
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Programming II (CS300) Chapter 07: Linked Lists and Iterators
ArrayLists 22-Feb-19.
Collections Framework
Data Representation Methods
Data Representation Methods
TCSS 143, Autumn 2004 Lecture Notes
CSE 143 Lecture 21 Advanced List Implementation
Presentation transcript:

SNU IDB Lab. Ch5. Linear Lists – Array Representation © copyright 2006 SNU IDB Lab.

SNU IDB Lab. Data Structures 2 Bird’s-Eye View Ch.5 ~ Ch.7: Linear List Ch. 5 – array representation Ch. 6 – linked representation Ch. 7 – simulated pointer representation ※ In succeeding chapters - matrices, stacks, queues, dictionaries, priority queues Java’s linear list classes java.util.ArrayList Java.util.Vector java.util.LinkedList In an array representation of linear list Elements are stored in an array

SNU IDB Lab. Data Structures 3 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array Performance

SNU IDB Lab. Data Structures 4 Data Objects Data Object: A set of instances of values Boolean = {false, true} Integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S, M, T, W, Th, F, Sa} Individual instances of a data object Primitive (atomic) 3, 5, a, Z, Composed of instances of another data object Element: the individual components of an instance of an object good: an instance of String class g, o, o, d is four elements of good each element is an instance of the data object Letter

SNU IDB Lab. Data Structures 5 Definition: Data structure Data object + Relationships that exist among instances and elements Relationships among instances of integer 369 < = 284 Relationships among elements that comprise an instance is more significant than 6 9 is immediately to the right of 6 The relationships are usually specified by specifying operations on instances add, subtract, predecessor, multiply Our primary concern: the representation of data objects the implementation of the operations of interest for the data objects

SNU IDB Lab. Data Structures 6 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array Performance

SNU IDB Lab. Data Structures 7 Linear List (Ordered List) An ordered collection of elements Instances are of the form (e 0, e 1, e 2, …, e n-1 ) Where e i denotes a list element i : The index of e i n : The list length or size, n (>= 0) is finite L = (e 0, e 1, e 2, e 3, …, e n-1 ) Relationships e 0 is the zero ’ th (or front) element e n-1 is the last element e i immediately precedes e i+1

SNU IDB Lab. Data Structures 8 Linear List Examples Students in COP3530 = (Jack, Jill, Abe, Henry, Mary, …, Judy) Exams in COP3530 = (exam1, exam2, exam3) Grades in COP3530 = ( “ Jack A+ ”, “ Jill B- ”, “ Abe D ”, … “ Judy F ” ) Days of Week = (S, M, T, W, Th, F, Sa) Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)

SNU IDB Lab. Data Structures 9 LinearList operations Suppose L = (a, b, c, d, e, f, g) size() : Determine list size L.size() = 7 get(index) : Get element with given index get(0) = a get(2) = c get(4) = e get(-1) = error get(9) = error indexOf(element) : Determine the index of an element indexOf(d) = 2 indexOf(a) = 0 indexOf(z) = -1 remove(index) : Remove and return element with given index. remove(2) returns c, L becomes (a,b,d,e,f,g), indices of d,e,f and g are decreased by 1 remove(-1)  error remove(20)  error add(index, element) : Add an element so that the new element has a specified index. add(0,h)  L = (h,a,b,c,d,e,f,g) // indices of a,b,c,d,e,f, and g are increased by 1 add(2,h)  L = (a,b,h,c,d,e,f,g) // indices of c,d,e,f, and g are increased by 1 add(10,h)  error add(-6,h)  error

SNU IDB Lab. Data Structures 10 Data Structure Specification Abstract Data Type (ADT) Specification of The instances The operations to be performed Language independent All representation of the ADT must satisfy the specification A way to validate the representation Hiding the details of implementation Two ways of ADT specification in Java Interface Abstract class

SNU IDB Lab. Data Structures 11 Abstract Data Type LinearList AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations isEmpty(): return true iff the list is empty, false otherwise size(): return the list size (i.e., number of elements in the list) get(index): return the indexth element of the list indexOf(x):return the index of the first occurrence of x in the list, return -1 if x is not in the list remove(index): remove and return the indexth element, elements with higher index have their index reduced by 1 add(theIndex, x): insert x as the indexth element, elements with theIndex >= index have their index increased by 1 output(): output the list elements from left to right }

SNU IDB Lab. Data Structures 12 Interface in Java A named collection of method definitions Does not provide any implementation (no nonabstract methods) A class implements an interface A class that implements the interface agrees to implement all of the methods defined in the interface Useful for Capturing similarities between unrelated classes Declaring methods that one or more classes are expected to implement Revealing an object's programming interface without revealing its class

SNU IDB Lab. Data Structures 13 Abstract class in Java Two types of classes in java Abstract and Nonabstract Default type is Nonabstract Abstract class Contains zero or more abstract methods Abstract method: implementation is not provided Can also contain nonabstract methods You cannot create an instance of an abstract class A class extends an abstract class (as usual classes)

SNU IDB Lab. Data Structures 14 Abstract class vs. Interface Abstract class or interface ? An abstract class can define nonconstant data members and nonabstract methods If only constants and abstract methods are needed  interface will do A class can implement many interfaces but can extend at most one class Only single inheritance among classes Multiple inheritance is simulated using interfaces Data Structures in this Text Use interfaces to specify ADTs throughout this lecture Exception is Graph in Chapter 17 (The abstract class Graph) Java specifies all of its data structures as interfaces Ex) java.util.Map, java.util.Set

SNU IDB Lab. Data Structures 15 The Java Interface: LinearList public interface LinearList { public boolean isEmpty(); public int size(); public Object get(int index); public int indexOf(Object elem); public Object remove(int index); public void add(int index, Object obj); public String toString(); } public class ArrayLinearList implements LinearList { // code for all LinearList methods must be provided here by the user }

SNU IDB Lab. Data Structures 16 The Java Abstract Class: LinearListAsAbstractClass public abstract class LinearListAsAbstractClass { public abstract boolean isEmpty(); public abstract int size(); public abstract Object get(int index); public abstract int indexOf(Object theElement); public abstract Object remove(int index); public abstract void add(int index, Object theElement); public abstract String toString(); } public class ArrayLinearList extends LinearListAsAbstractClass { // code for all abstract classes of LinearListAsAbstractClass must come here } ArrayLinearList inherits “implemented nonabstract methods”

SNU IDB Lab. Data Structures 17 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array

SNU IDB Lab. Data Structures 18 The Array Representation public class ArrayLinearList implements LinearList { protected Object[] element; // no array size declaration in Java protected int size; // no of elements in array // … element = new Object[initialCapacity]; // initialization } Use a one-dimensional array element[] L = (a, b, c, d, e) Store element i of linear list into element[i] location(i) = i abcde

SNU IDB Lab. Data Structures 19 Various mapping strategies Right to Left mapping  location (i) = last - i abcde Mapping that skips every other position a bcde Wrap around mapping  location (i) = (7 + i) % 15 abcde Put element i of list in element[i] abcde size = 5 Use a variable size to record current number of elements

SNU IDB Lab. Data Structures 20 Add/Remove An Element abcde agbcde add(1,g) Add ag cde remove(3) Remove size = 5 size = 6 size = 5

SNU IDB Lab. Data Structures 21 Declaring Array in Java Primitive Data Types (declaration and initialization) int[] anArray; anArray = new int[10]; int anArray[]; anArray = new int[10]; Non-Primitive Data Types (declaration only) Auto[] KoreanCar; KoreanCar = new Auto[10]; Auto KoreanCar[]; KoreanCar = new Auto[10]; ** initialization needs a for loop int[] anArray= new int[10]; int anArray[] = new int[10]; Auto[] KoreanCar = new Auto[10]; Auto KoreanCar[] = new Auto[10];

SNU IDB Lab. Data Structures 22 “element” array of type “Object” Syntax: Object[] element or Object element[] element[] hold references to elements of any user-defined data type Data type of element is unknown Cannot put elements of primitive data types (int, float, double, char) Instead, Use corresponding Class – Integer, Float, Double, Character, etc. Array Length Don ’ t know how many elements will be in list Must pick an initial length Dynamically increase the length as needed by the user

SNU IDB Lab. Data Structures 23 Increasing Array Length Define an array of the new length Copy the n elements from old array to the new array  θ (n) Change the references to the new array // create a new array of proper length and data type Object[] newArray = new Object[newLength]; // copy all elements from old array “element” into new one “newArray” System.arrayCopy(element, 0, newArray, 0, element.length); // change the reference element = newArray;

SNU IDB Lab. Data Structures 24 Space Complexity (1) Increase the array size 1 by 1 element = new char [6] MaxListSize=6 newArray = new char[7]; newLength=7 Space needed during array copying 2 * newLength – 1 = 2 * maxListSize + 1 abcdef

SNU IDB Lab. Data Structures 25 Space complexity (2) The array length is normally doubled wherever the array becomes full. abcdef newArray = new char[12]; newLength = 12 abcdef maxListSize increased by *2  newLength Space needed = 1.5 * newLength = 3 * maxListSize element maxListSize = 6

SNU IDB Lab. Data Structures 26 How Big Should The New Array Be? (1) By doubling the array, the complexity (num of copy) is θ (n) T(n) = … + 2 k = θ (2 k+1 – 1) = θ (2n – 3) = θ (n) Process# of addsCost ■ → ■□ 11 ■■ → ■■□□ 22 ■■■□ 30 ■■■■ → ■■■■□□□□ 44 ■■■■■□□□ 50 ■■■■■■□□ 60 ■■■■■■■□ 70 ■■■■■■■■ → ■■■■■■■■□□□□□□□□ 88 ……… 2 k → 2 k+1 n-1 (= 2 k )2k2k n (= 2 k +1)0

SNU IDB Lab. Data Structures 27 How Big Should The New Array Be? (2) By increasing the length by 1, the complexity of becoming an array with size n is θ (n 2 ) After n-1 adds, the array size is now n T(n) = … + (n – 1) = θ ((n 2 – n) / 2) = θ (n 2 ) ProcessCost (No of Copy) ■ → ■□ 1 ■■ → ■■□ 2... n – 1 → nn – 1

SNU IDB Lab. Data Structures 28 Insert theElement with array doubling Public void add(int index, Object theElement) { if (index size) //invalid index throw new IndexOoutOfBoundsException (…); if (size == element.length) { // no space  double capacity Object[] newArray = new Object[2*size]; System.arraycopy(element, 0, newArray, 0, size); element = newArray; } for (int i = size-1; i >=index; i--) element[i+1] = element[i]; // move up the remaining elements element[index] = theElement; Size++; }

SNU IDB Lab. Data Structures 29 Java’s Linear List Classes Vector size():int elementAt(index:int):Object addElement(o:Object):void removeElement(o:Object):boolean util java ArrayList size():int get(index:int):Object add(o:Object):boolean remove(o:Object):boolean LinkedList size():int get(index:int):Object add(o:Object):boolean remove(o:Object):boolean 연산속도는 ArrayList 가 조금 빠름 Vector 는 size 에 신경쓸 필요가 없음 내부구현 : Vector  vector ArrayList  array LinkedList  reference

SNU IDB Lab. Data Structures 30 The Class ArrayLinearList (ALL) : program 5.4 — 5.8 public class ArrayLinearList implements LinearList{ protected Object[] element; protected int size;... public boolean isEmpty() { return (size == 0); } public int size() { return size; } public Object get(int index) { return element[index]; } public int indexOf(Object theElement) { …..} public Object remove(int index) { Object removedElement = element[index]; for (int i = index + 1; i < size; i++) element[i-1] = element[i]; element[--size] = null; return removedElement; } public void add(int index, Object theElement) { …….} } * FastArrayLinearList (FALL) : System.arraycopy() instead of for loop in remove() and add()

SNU IDB Lab. Data Structures 31 Implementing ArrayLinearList (1) Constructor With initial capacity With default capacity (say, 10 elements) Removing an Element Ascertain that the list contains an indexed element (if not, exception) Shift index+1,…, size-1 elements down (left) one position Complexity = O(size – index) Reduce the value of size by 1

SNU IDB Lab. Data Structures 32 Implementing ArrayLinearList (2) Inserting an Element Move index ~ size-1 elements one position up (right) Complexity = O(size – index + 1) Insert the new element in position index Increment size by 1 Decreasing the Length of element To enable the linear list to free some of the array space when the list size becomes small slight modification of the method remove Iterator Navigate elements of linear list

SNU IDB Lab. Data Structures 33 Iterator: Basic Concepts Specifies a unified mechanism to examine the elements in an object one at a time Related methods are in the interface java.util.Iterator ※ With iterator methods we can easily examine ArrayLinearList ’s all elements Iterator ix = x.iterator(); Constructs and initializes an iterator to examine the elements of x constructed iterator is assigned to ix You must define & implement the method iterator() in the class for x

SNU IDB Lab. Data Structures 34 Iterator: Methods 2 Main Methods ix.hasNext() Returns true iff x has a next element ix.next() Throws NoSuchElementException if there is no next element Returns next element otherwise Optional Method ix.remove() Removes last element returned by ix.next() Throws UnsupportedMethodException if method not implemented Throws IllegalStateException if ix.next() not yet called or did not return an element

SNU IDB Lab. Data Structures 35 Example using an Iterator By iterator (more general) Iterator ix = x.iterator(); while (ix.hasNext()) examine(ix.next()); vs By index (only for indexed data structure) for (int i=0; i<x.size(); i++) examine(get(i));

SNU IDB Lab. Data Structures 36 An Iterator for ArrayLinearList (1/3) By using a top-level class Implemented as a separate class from “Iterator” interface Iterator class must access ArrayLinearList class data member class ArrayLinearListIterator implements Iterator { private ArrayLinearList list; private int nextIndex; public ArrayLinearListIterator(ArrayLinearList theList) { list = theList; nextIndex = 0; } public boolean hasNext() { return nextIndex < list.size; } // access list’s data member directly // … }

SNU IDB Lab. Data Structures 37 public class ArrayLinearListWithIterator implements LinearList { public Iterator iterator() {return new ArrayLinearListIterator();} private class ArrayLinearListIterator implements Iterator { public boolean hasNext() { return nextIndex < size; } // … } // … all ArrayLinearList members and operations } By using a member class Implemented as a member class (nested class) of list class Can access private data members of enclosing class Can define the iterator in the same file An Iterator for ArrayLinearList (2/3)

SNU IDB Lab. Data Structures 38 An Iterator for ArrayLinearList (3/3) Using a member class is better than using a top-level class because list and iterator implementation can be separated ArrayLinearListWithIterator isEmpty():boolean size():int get(index:int):Object remove(index:int):Object iterator():Iterator... ArrayLinearListIterator hasNext():boolean next():Object remove():void uses

SNU IDB Lab. Data Structures 39 Merits of an Iterator It is often possible to implement the method next() so that its complexity is less than that of get() Public Object get(int Index) { checkIndex(index); return element[Index]} Public Object next() { if (nextIndex < list.size) return list.element[nextIndex++]; else throw new NoSuchElementException( “ No next element ” )} TP page 45 Iterators provide a uniform way to sequence through the elements of a data structure regardless of the data structure Iterators provide left-to-right access vs Get() gives bidirection

SNU IDB Lab. Data Structures 40 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array Performance

SNU IDB Lab. Data Structures 41 java.util.Vector One of most widely used data structure class in java Can think as array with variable length! Have many operations similar to that of LinearList Operations boolean add(Object o) boolean add(int index, Object o) Object remove(int index) boolean remove(Object o) int size() boolean isEmpty() int indexOf(Object o) void removeAllElements()

SNU IDB Lab. Data Structures 42 Remember “LinearList” interface public interface LinearList { public void add(int index, Object obj); public Object remove(int index); public boolean isEmpty(); public int size(); public Object get(int index); public int indexOf(Object elem); public String toString(); }

SNU IDB Lab. Data Structures 43 Array vs. Vector in Java Object[] oa = new Object[3]; //using array oa[0] = “A”; oa[1] = “B”; oa[2] = “C”; oa[3] = “D”; // size increasing must be done manually Vector v = new Vector(3); //using vector v.add(“A”) v.add(“B”) v.add(“C”) v.add(“D”) // size is increased automatically (new size is now 6)

SNU IDB Lab. Data Structures 44 Linear List using Vector LLAVS Public class LinearListAsVectorSubclass extends Vector implements LinearList { // Program 5.13} LLAV Public class LinearListAsVector {// Program 5.14: element = new Vector(initialSize)}

SNU IDB Lab. Data Structures 45 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array Performance

SNU IDB Lab. Data Structures 46 Multiple Lists in a Single Array Map all of lists into a single array element whose length is the maximum possible May need shift left or right sub-array when inserting an element in list I Utilize the allocated array space …… front[1]last[1]front[2]front[3]last[3] last[2]

SNU IDB Lab. Data Structures 47 Table of Contents Data Objects and Structures The Linear List Data Structure Array Representation Vector Representation Multiple Lists in a Single Array Performance

SNU IDB Lab. Data Structures 48 Performance Measurement operation class get insertremove best- case average worst- case best- case average worst- case ArrayLinearList 5.6ms26.2ms70s140s6.9ms71s142s FastArrayLinearList 5.6ms31.2ms5.8s11.8s8.6ms5.7s11.7s LinearListAsVector 20.8ms51.2ms5.8s11.8s18.4ms5.8s11.8s LinearListAsVectorS ubclass 18.6ms48.2ms5.8s11.8s22.4ms5.8s11.8s (List is constructed with the default initial capacity of 10) Implement and measure the 4 classes in the textbook ALL in page FALL in page 167 LLAV in page LLAVS in page 177

SNU IDB Lab. Data Structures 49 Summary Ch.5 ~ Ch.7: Linear List Ch. 5 – array representation ADT LinearList, Java’s Interface & Abstract Class Array representation: Increasing array size, Iterator Vector representation Ch. 6 – linked representation Ch. 7 – simulated pointer representation ※ In succeeding chapters - matrices, stacks, queues, dictionaries, priority queues Java’s linear list classes java.util.ArrayList, java.util.Vector, java.util.LinkedList

SNU IDB Lab. Data Structures 50 JDK class: java.util.ArrayList public class ArrayList extends AbstractList { constructors ArrayList(): Constructs an empty list with initial size 10 ArrayList(int cap): Constructs an empty list with initial size cap methods boolean add(Object obj): Adds obj to the end of the list; Always returns true Object get(int i): Returns i-th element of the list boolean isEmpty(): Returns true iff the list is empty, false otherwise boolean remove(Object obj): Removes obj from the list ; Returns true iff obj was in the list }

SNU IDB Lab. Data Structures 51 JDK class: java.util.vector public class Vector extends AbstractList { constructors Vector(): Constructs an empty vector with initial size 10 Vector(int cap): Constructs an empty vector with initial size cap methods void addElement(Object obj): Adds obj to the end of the vector Object elementAt(int i): Returns i-th element of the vector boolean isEmpty(): Returns true iff the vector is empty, false otherwise boolean remove(Object obj): Removes obj from the vector; Returns true iff obj was in the vector }