14.1 The java.util Package.

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.
Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Chapter 19 Java Data Structures
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
Collections. Why collections? Collections are used to hold a collection of objects. List holds objects based on order of insertion and can hold non unique.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
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.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
1 Java's Collection Framework By Rick Mercer with help from The Java Tutorial, The Collections Trail, by Joshua BlockThe Collections Trail.
Big Java Chapter 16.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
Chapter 18 Java Collections Framework
תוכנה 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.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Data structures and algorithms in the collection framework 1.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Building Java Programs Bonus Slides Hashing. 2 Recall: ADTs (11.1) abstract data type (ADT): A specification of a collection of data and the operations.
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.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
1 Copyright © 2011 Tata Consultancy Services Limited COLLECTIONS By TEAM 5 Rajendhiran Sivan Christi Yashwanth Bijay Smruthi Satyajit.
University of Limerick1 Collections The Collection Framework.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
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.
©Karsten Lundqvist Example: Array and Arrays 1 import java.util.*; public class Example { private int intValues[] = { 1, 2, 3, 4, 5, 6 }; private double.
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.
Java Collections CHAPTER 3-February-2003
Slides by Donald W. Smith
Using the Java Collection Libraries COMP 103 # T2
Chapter 19 Java Data Structures
Chapter 20 Lists, Stacks, Queues, and Priority Queues
JAVA COLLECTIONS LIBRARY
University of Central Florida COP 3330 Object Oriented Programming
ARRAYLIST AND VECTOR.
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
Data Structures and Database Applications Abstract Data Types
Road Map CS Concepts Data Structures Java Language Java Collections
Java Collections Overview
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Lecture 6: Collections.
Collections Not in our text.
CS2110: Software Development Methods
Collections Framework
CSE 1020: The Collection Framework
Trees in java.util A set is an object that stores unique elements
CS 240 – Advanced Programming Concepts
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Introduction to Java Collection
Presentation transcript:

14.1 The java.util Package

14.1.1 The java.util package Predefined utility classes to: Manage collections of objects Manage communication between objects Manipulate information within objects

14.2.1 Understanding collections Collections are objects that reference a group of objects Unlike arrays, collections can only reference the Object data type This means that any object can be stored in a collection, but casting is required to retrieve the object Collections can: Change size Provide sorting Support adding and deleting elements

14.2.2 Collection storage technologies Array: Fixed size, fast & efficient to access, difficult to modify Linked List: Elements have references to the preceeding and following element, easy to change, slow to search Tree: Easy to change, stores elements in order Hashtable: Uses an indexing key to identify elements. Elements are retrieved from the hashtable using the element’s key

14.2.4 Types of collections Collection List Set Map Simple container of unordered objects. Duplicates are permitted List Container of ordered elements. Duplicates are permitted Set Unordered collection of objects in which duplicates are not permitted Map Collection of key/value pairs. The key is used to index the element. Duplicate keys are not permitted

14.3.2 Collection interfaces Defines behavior of collection objects Hierarchy of six interfaces

14.3.3 Collection classes

14.3.4 Set objects HashSet implements the Set interface. Duplicates are not permitted TreeSet implements OrderedSet. Includes methods to take advantage of the ordering, eg: TreeSet.first() TreeSet.last() TreeSet.headSet() TreeSet.subSet()

14.3.5 List objects Vector ArrayList LinkedList A collection of objects. Implements the List interface. Grows as necessary. Retains the order in which the objects were added ArrayList Resizable, ordered array LinkedList Each element has a reference to the preceeding and following element

14.3.6 Map objects Use a unique key to reference the element Key determines where the element is stored The hashCode() method of the Object class can be overridden to provide unique keys

14.3.7 Iterators Provide a method for stepping through collections Iterating through a set is non-deterministic Use the ListIterator class for iterating through lists

14.3.8 Sorting and shuffling list objects Collection has methods for sorting Collection.sort() sorts the entire list or a subsection Collection.reverse() reverses the current list Shuffling moves elements within the list Collection.shuffle() Collection.shuffle(Random r)