And the list goes on and on and on….

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
COMP 121 Week 11: Linked Lists. Objectives Understand how single-, double-, and circular-linked list data structures are implemented Understand the LinkedList.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
1 Collections Working with More than One Number or Data Type or Object.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
Chapter 19 Java Data Structures
Chapter 5 Ordered List. Overview ● Linear collection of entries  All the entries are arranged in ascending or descending order of keys.
Lists Based on content from: Java Foundations, 3rd Edition.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Abstract Data Types. What’s on the menu? What’s an abstract data type? How do you implement it? ADT List.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Data structures Abstract data types Java classes for Data structures and ADTs.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
List Interface and Linked List Mrs. Furman March 25, 2010.
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
Using the Java Collection Libraries COMP 103 # T2
Review Array Array Elements Accessing array elements
Chapter 5 Ordered List.
Sixth Lecture ArrayList Abstract Class and Interface
Copy Constructor / Destructors Stacks and Queues
Chapter 19 Java Data Structures
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Abstraction A tool (concept) to manage complexity
JAVA COLLECTIONS LIBRARY
JAVA COLLECTIONS LIBRARY
COMP 121 Week 9: ArrayList.
ARRAYLIST AND VECTOR.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Arrays and the ArrayList Class The ArrayList Class
Data Structures and Database Applications Abstract Data Types
Lecture 9 Concepts of Programming Languages
Object Oriented Programming COP3330 / CGS5409
TCSS 143, Autumn 2004 Lecture Notes
Arrays and Linked Lists
List Data Structure.
Chapter 20 Lists, Stacks, Queues, and Priority Queues
ArrayLists.
Arrays versus ArrayList
List Implementations Chapter 9.
Array Based Collections
Object-Oriented Programming Paradigm
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Chapter 5 Ordered List.
ArrayLists 22-Feb-19.
Dynamic Data Structures and Generics
Introduction to Data Structure
Review: libraries and packages
Arrays © 2014 Goodrich, Tamassia, Goldwasser Arrays Vectors
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Why not just use Arrays? Java ArrayLists.
Lecture 9 Concepts of Programming Languages
Introduction to Java Collection
Presentation transcript:

And the list goes on and on and on….

Advantages of a List Like an array, a List is set up to store multiple items. But it has several advantages: It can be dynamically expanded to make room for more items. Items can be removed and inserted anywhere with ease. It has several other methods such as contains which gives it much more utility than an array. The one disadvantage is that it can not store primitives. But there is a work around to this which we will cover latter.

Design of a List There are several ways that Lists are set up such. There are ArrayLists, LinkedLists, Stack, Vector, etc. Each implementation has the same interface. But encapsulation allows us to have different implementations.

ArrayList The one specific type of list that we will be using will be an ArrayList. It’s implementation includes using an array inside the ArrayList class. But things like expanding the ArrayList, adding items in order, and other things are taken care of for us inside the ArrayList class. Encapsulation for the win!

Adding and Removing at an index Given the following items were in an ArrayList called letters: {“A”, “B”, “C”, “D”, “E”, “F”} This is how the ArrayList would change after the following method calls: letters.add(“X”); {“A”, “B”, “C”, “D”, “E”, “F”, “X”} letters.add(1, “Y”); {“A”, “Y”, “B”, “C”, “D”, “E”, “F”, “X”} letters.remove(4); {“A”, “Y”, “B”, “C”, “E”, “F”, “X”} letters.set(0, “Z”); {“Z”, “Y”, “B”, “C”, “E”, “F”, “X”}

A collection of objects Lists by default are designed to store any object. This allows you to add an object of any type to a list. But this can be problematic since you can not be certain of the type of the object that you obtain from the list. Think of it like having a big box that you can put all different types of household items into. It is convenient to do so until you want a hammer and you pull out a scarf.

Declaring it with a type You can restrict the type of objects that a list stores in the following manner Declared without a type: ArrayList carLot = new ArrayList(); carLot.add(new Car(“Camry”)); carLot.add(new Toy(“Elmo”)); ((Car)carLot.get(0)).run(); Declared with a type: ArrayList<Car> carLot = new ArrayList<Car>(); carLost.get(0).run(); In the second example, only Car objects can be added to the list and you don’t have to cast objects returned from the list as a Car to call Car methods