Processing Data in Collections Chapter 13. 13 Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 The Collections API.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Concrete collections in Java library
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Hash Tables,
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
Chapter 14 Introduction to Collections
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.
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++)
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
AbstractClassesInterfacesPolymorphism1 Abstract Classes, Interfaces, Polymorphism Barb Ericson Georgia Tech April 2010.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
1 L41 Collections (1). 2 OBJECTIVES  What collections are.  To use class Arrays for array manipulations.  To use the collections framework (prepackaged.
Java Collections. Lecture Objectives To understand the concepts of Java collections To be able to implement Java programs based on Collections.
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 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
Chapter 19 Java Data Structures
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
(c) University of Washington14-1 CSC 143 Java Collections.
The Java Collections Framework (JCF) Introduction and review 1.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Chapter 11 Arrays Continued
Big Java Chapter 16.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Lists and the Collection Interface Review inheritance & collections.
Chapter 18 Java Collections Framework
Computer Science 209 Software Development Java Collections.
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
Data structures Abstract data types Java classes for Data structures and ADTs.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
16-August-2002cse Libraries © 2002 University of Washington1 Class Libraries CSE 142, Summer 2002 Computer Programming 1
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
Recitation 7 Collections. Array List and Linked List Array List and Linked List are implementations of the same interface: List. As a result, they have.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
University of Limerick1 Collections The Collection Framework.
Interfaces. In order to work with a class, you need to understand the public methods  methods, return types,…  after you instantiate, what can you do.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 21 Sets and Maps.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Chapter 21 Sets and Maps Jung Soo (Sue) Lim Cal State LA.
Slides by Donald W. Smith
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 19 Java Data Structures
Sets, Maps and Hash Tables
Collections Framework
CSE 1020: The Collection Framework
Presentation transcript:

Processing Data in Collections Chapter 13

13 Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects. Primitives must be wrapped in special wrapper objects. Wrappers exist for each of the eight primitive types.

13 What is an iterator? An iterator is an object that encapsulates the ability to iterate through or visit each element in the collection.

13 Using the Iterator Interface hasNext() method determines if there are more elements in the array next() method returns the next element and advances the iterator

13 The DrawShapes Application User clicks in applet window to create one of three random shapes. Each shape is added to a collection. When user clicks in applet window, the collection is checked to see if a “hit” is registered on an existing shape. When a “hit” occurs, the shape’s color will change randomly.

13 The Shape Inheritance Hierarchy Abstract class OurShape implements: changeColorRandomly() to change the color of an object by randomly selecting a color contains() to determine whether x, y coordinates of a mouse click fall within a shape’s boundaries draw() to draw the shape at x, y coordinates specified by a mouse click

13 Classes Derived from OurShape OurRectangle OurTriangle OurCircle

13 What is a linked list? A LinkedList is a more powerful data structure that allows for quick and easy insertion and removal of elements.

13 Linked Lists LinkedLists come in two types: Singly linked list—each node knows only the next node Doubly linked list—each node knows both the previous and the next node

13 What is a set? A set is a collection with no duplicate elements. Programmer needs to determine what constitutes a “duplicate.” The equals() method can be used to provide an additional definition of equality.

13 HashSet Based on a hash table, a HashSet is a powerful data structure that can be used to retrieve objects quickly in a set. Unordered collection A hash code is used to organize objects in a HashSet

13 TreeSet TreeSet provides the properties of a set in a sorted collection. Objects can be inserted in any order but are retrieved in sorted order Uses Comparable interface to compare objects for sorting Primitive types and String objects are comparable Up to programmer to implement the compareTo() method for user-defined objects