Java Collections Framework A presentation by Eric Fabricant.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 21 Generics.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L16 (Chapter 22) Java Collections.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 8.
Java Collections. Lecture Objectives To understand the concepts of Java collections To be able to implement Java programs based on 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.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
Chapter 19 Java Data Structures
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
Java's Collection Framework
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/21) Collections Joel Adams and Jeremy Frens Calvin College.
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 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.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
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.
1 Java's Collection Framework By Rick Mercer with help from The Java Tutorial, The Collections Trail, by Joshua BlockThe Collections Trail.
(c) University of Washington14-1 CSC 143 Java Collections.
Data structures and algorithms in the collection framework 1 Part 2.
Sets Recall from chapter 22 that one of the Collection subclasses is the Set – A Set is a list in which there are no duplicate entries, which you might.
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
Computer Science 209 Software Development Java Collections.
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
Collections –data structures and Algorithms L. Grewe.
Data structures and algorithms in the collection framework 1.
Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07.
Arrays, ArrayLists, and Collections. Rationale Suppose we have a program to compute the average of three numbers. We could write a simple little method.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
©SoftMoore ConsultingSlide 1 Java Collections Framework.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
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.
Maps Nick Mouriski.
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.
Starting Out with Java From Control Structures through Data Structures by Tony Gaddis and Godfrey Muganda Collections in Java.
1 Collections. 2 Concept A collection is a data structure – actually, an object – to hold other objects, which let you store and organize objects in useful.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 21 Sets and Maps.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
©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 OOP tirgul No
Chapter 19 Java Data Structures
Software Development Java Collections
University of Central Florida COP 3330 Object Oriented Programming
Road Map CS Concepts Data Structures Java Language Java Collections
Java Collections Overview
Lecture 6: Collections.
14.1 The java.util Package.
Collections Framework
CS 240 – Advanced Programming Concepts
Presentation transcript:

Java Collections Framework A presentation by Eric Fabricant

What is it? “The Collections Framework provides a well-designed set of interfaces and classes for storing and manipulating groups of data as a single unit, a collection.” -java.sun.com

So what? Well, The framework provides a convenient API to many of the abstract data types familiar to computer science: maps, sets, lists, trees, arrays, hashtables and other collections.

What does it look like?

The Basics simple, but not really. Set List Map Set List Map

What makes a Set a Set? No duplicate elements are allowed, such that e1.equals(e2) is true. No duplicate elements are allowed, such that e1.equals(e2) is true.

More on Sets The Set Interface extends the Collection Interface. AbstractSet implements Set and extends AbstractCollection AbstractSet is a convenience class that contains basic concrete implementation. The Set Interface extends the Collection Interface. AbstractSet implements Set and extends AbstractCollection AbstractSet is a convenience class that contains basic concrete implementation.

Types of Sets HashSet LinkedHashSet TreeSet HashSet LinkedHashSet TreeSet

HashSet Implements the Set interface, backed by a hash table (actually a HashMap instance). Makes no guarantees as to the iteration order of the set. It does not guarantee that the order will remain constant over time. Permits the null element. Implements the Set interface, backed by a hash table (actually a HashMap instance). Makes no guarantees as to the iteration order of the set. It does not guarantee that the order will remain constant over time. Permits the null element.

LinkedHashSet Extends HashSet. Implements doubly-linked list. Can retrieve elements based on insertion-order. Less efficient than HashSet. Extends HashSet. Implements doubly-linked list. Can retrieve elements based on insertion-order. Less efficient than HashSet.

TreeSet Extends AbstractSet, implements SortedSet Elements can be kept in acscending order according to compareTo() or compare() All elements must be comparable. Extends AbstractSet, implements SortedSet Elements can be kept in acscending order according to compareTo() or compare() All elements must be comparable.

Any questions?

What makes a List a List? Duplicate elements are allowed and position-oriented operations are permitted.

More on Lists The List Interface extends the Collection Interface. AbstractList implements List and extends AbstractCollection AbstractList is a convenience class that contains basic concrete implementation. The List Interface extends the Collection Interface. AbstractList implements List and extends AbstractCollection AbstractList is a convenience class that contains basic concrete implementation.

Types of Lists ArrayList LinkedList Vector Stack ArrayList LinkedList Vector Stack

ArrayList Extends AbstractList Auto-resizeable. Based on a simple array. Permits the null element. Extends AbstractList Auto-resizeable. Based on a simple array. Permits the null element.

LinkedList Extends AbstractSequentialList, which extends AbstractList Similar to ArrayList Different implementation based on nodes that contain data and links to other nodes. Extends AbstractSequentialList, which extends AbstractList Similar to ArrayList Different implementation based on nodes that contain data and links to other nodes.

Nodes In Action

Vector Similar to ArrayList Contains synchronized methods. Similar to ArrayList Contains synchronized methods.

Stack Extends Vector “Last in, First Out” behavior Contains methods to allow typical Stack behaviors. (ie: push(), pop(), etc. ) Extends Vector “Last in, First Out” behavior Contains methods to allow typical Stack behaviors. (ie: push(), pop(), etc. )

Any questions?

What makes a Map a Map? The collection is kept in key/value pairs. Any object can be a key or value. No duplicate keys allowed. The collection is kept in key/value pairs. Any object can be a key or value. No duplicate keys allowed.

More on Maps The Map Interface does not extend the Collection Interface. AbstractMap implements Map and does not extend AbstractCollection AbstractMap is a convenience class that contains basic concrete implementation. The Map Interface does not extend the Collection Interface. AbstractMap implements Map and does not extend AbstractCollection AbstractMap is a convenience class that contains basic concrete implementation.

Types of Maps TreeMap HashMap LinkedHashMap TreeMap HashMap LinkedHashMap

TreeMap Implements SortedMap, extends AbtractMap Keys can be kept in acscending order according to compareTo() or compare() Implements SortedMap, extends AbtractMap Keys can be kept in acscending order according to compareTo() or compare()

HashMap Implements SortedMap, extends AbstractMap Permits the null element. Makes no guarantees as to the iteration order of the set. Implements SortedMap, extends AbstractMap Permits the null element. Makes no guarantees as to the iteration order of the set.

More HashMap It does not guarantee that the order will remain constant over time. Can retrieve elements based on insertion-order or access order. It does not guarantee that the order will remain constant over time. Can retrieve elements based on insertion-order or access order.

LinkedHashMap Extends Hashmap Implements doubly-linked list. Extends Hashmap Implements doubly-linked list.

Any questions?

Collections Class Contains static methods for operating on collections and maps. Quite usefull :-) Contains static methods for operating on collections and maps. Quite usefull :-)

Arrays Class Contains static methods sorting and searching arrays, comparing arrays, and filling array elements.

Additional Info Synchronized Collection classes can be found in java.util.Collections

( the end )

Credits Material Adapted from: Java Programming, 5th ed. by Y. Daniel Liang & Java.sun.com Material Adapted from: Java Programming, 5th ed. by Y. Daniel Liang & Java.sun.com