ArrayList.

Slides:



Advertisements
Similar presentations
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
Advertisements

CSC 205 – Java Programming II Lecture 25 March 8, 2002.
5-May-15 ArrayLists. 2 ArrayList s and arrays A ArrayList is like an array of Object s Differences between arrays and ArrayList s: Arrays have special.
CS 106 Introduction to Computer Science I 04 / 30 / 2007 Last lecture :( Instructor: Michael Eckmann.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
CS 106 Introduction to Computer Science I 04 / 27 / 2007 Instructor: Michael Eckmann.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
15-Jun-15 Lists in Java Part of the Collections Framework.
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
25-Jun-15 Vectors. 2 Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: Arrays have special syntax; Vector.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
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.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
12-Jul-15 Lists in Java Part of the Collections Framework.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
1 ArrayList  Array’s are limited because we need to know the size before we use them.  An ArrayList is an extension of an array that grows and shrinks.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
CS 106 Introduction to Computer Science I 04 / 25 / 2007 Instructor: Michael Eckmann.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
ArrayList, Multidimensional Arrays
CSE 143 Lecture 4 ArrayList Reading: 10.1 slides created by Marty Stepp
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.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
CS 106 Introduction to Computer Science I 04 / 25 / 2008 Instructor: Michael Eckmann.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
List data type(ADT). Lists Elements : a 1,a 2,a 3,… a i-1,a i, a i+1,…a n Null List contains: 0 elements Types of Operations on list 1.Insertion 2.Deletion.
Object-Oriented Programming (Java) Review Unit 1 Class Design Basic Console I/O StringTokenizer Exception UML class diagram.
Object Oriented Programming in Java Habib Rostami Lecture 7.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
1 CS162: Introduction to Computer Science II Abstract Data Types.
EKT472: Object Oriented Programming
Chapter 5: The List Abstract Data Type
Data Structures Lakshmish Ramaswamy.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Implementing ArrayList Part 1
Introduction to OO Program Design
The ArrayList Class An ArrayList object stores a list of objects, and is often processed using a loop The ArrayList class is part of the java.util package.
Introduction to Collections
Introduction to Collections
TCSS 143, Autumn 2004 Lecture Notes
ArrayLists.
Programming in Java Lecture 11: ArrayList
Introduction to Collections
Collections in Java The objectives of this lecture are:
Grouped Data Arrays, and Array Lists.
Computer Science and Engineering
Introduction to Collections
ArrayLists 22-Feb-19.
Introduction to Collections
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Linked Lists Chapter 5 (continued)
ArrayLists.
ArrayLists 27-Apr-19.
TCSS 143, Autumn 2004 Lecture Notes
Part of the Collections Framework
Recitation 2 CS0445 Data Structures
Arrays and ArrayLists.
Java Generics & Iterators
What can you put into an ArrayList?
Presentation transcript:

ArrayList

Methods tested on AP add size get set remove

Add add(int index, Object o) add(Object o) Inserts o at index in the list ex: band.add(1, “Ringo”); add(Object o) Inserts o at the end of the list ex: band.add(“John”);

Size size() returns the number of elements in the list return type int Ex: System.out.print(“Band size: “+ band.size());

Get get(int index) returns the Object at the given index since an Object is returned, casting is required in order to use the Object ex: String member = (String)band.get(1);

Set set(int index, Object o) Replaces the element at the specified position (index) in this list with o. ex: band.set(1, “George”); //replaces the object at position 1 with “George” Has a return type of Object ex: System.out.println(band.set(3,"Bob")); //this will print the object that Bob replaced

Remove remove(int index) Removes the element at the specified position (index) in this list. Returns an Object. the Object returned is the element that was removed ex: band.remove(1); ex: band.add(band.remove(1));

Other methods: clear() contains(Object elem) indexOf(Object elem) isEmpty() lastIndexOf(Object elem) removeRange(int fromIndex, int toIndex) toArray()

toString public String toString() Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object). This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.

Inherited Methods Methods inherited from class java.util. AbstractListequals, hashCode, iterator, listIterator, listIterator, subList  AbstractCollectioncontainsAll, remove, removeAll, retainAll, toString  Methods inherited from class java.lang. Objectfinalize, getClass, notify, notifyAll, wait, wait, wait  Methods inherited from interface java.util. ListcontainsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList