Collections A First Glimpse 16-Apr-19.

Slides:



Advertisements
Similar presentations
Java Programming: Advanced Topics 1 Collections and Utilities.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
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.
Collections Sets - no duplicates Lists - duplicates allowed Maps - key / value pairs A collection is an Object which contains other Objects. There are.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
15-Jun-15 Lists in Java Part of the Collections Framework.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
Java Collection Framework. Interface Collection add(o) Add a new element clear() Remove all elements contains(o) Membership checking. IsEmpty() Whether.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Collections A First Glimpse. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector is a kind of collection.
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.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
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.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
Sets and Maps Part of the Collections Framework. The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
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.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
The Java Collections Framework (JCF) Introduction and review 1.
Chapter 18 Java Collections Framework
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
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.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
University of Limerick1 Collections The Collection Framework.
4-Mar-16 Introduction to Collections. Revision questions True false questions 0 for False 1 for True Please do not answer anything other than the above.
Collections Dwight Deugo Nesa Matic
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
©Karsten Lundqvist Example: Array and Arrays 1 import java.util.*; public class Example { private int intValues[] = { 1, 2, 3, 4, 5, 6 }; private double.
CS2005 Week 7 Lectures Set Abstract Data Type.
Java Collections CHAPTER 3-February-2003
Slides by Donald W. Smith
Fundamental of Java Programming
Iterators.
Using the Java Collection Libraries COMP 103 # T2
Sets Set is an unordered list of items
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 19 Java Data Structures
Software Development Java Collections
Efficiency of in Binary Trees
Java Collections Overview
Introduction to Collections
Introduction to Collections
JAVA Collections Framework Set Interfaces & Implementations
TCSS 342, Winter 2006 Lecture Notes
Lecture 6: Collections.
Introduction to Collections
Introduction to Collections
Collections A First Glimpse.
CIT Nov-18.
Part of the Collections Framework
Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind.
Collections in Java The objectives of this lecture are:
Introduction to Collections
Introduction to Collections
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Web Design & Development Lecture 6
Part of the Collections Framework
Java Generics & Iterators
Abstract Data Types (ADTs)
Presentation transcript:

Collections A First Glimpse 16-Apr-19

Collections A collection is a structured group of objects An array is a kind of collection A Vector is a kind of collection A linked list is a kind of collection Java 1.2 introduced the Collections Framework and provided many great implementations Vectors have been redefined to implement Collection Trees, linked lists, stacks, hash tables, and other classes are implementations of Collection Arrays do not implement the Collection interfaces

Types of Collection Java supplies several types of Collection: Set: cannot contain duplicate elements, order is not important SortedSet: like a Set, but order is important List: may contain duplicate elements, order is important Java also supplies some “collection-like” things: Map: a “dictionary” that associates keys with values, order is not important SortedMap: like a Map, but order is important

The Collections hierarchy

Collections are ADTs I’m not going to cover Collections just yet, but I want to use them as an example Collections are one of the best-designed parts of Java, because They are elegant: they combine maximum power with maximum simplicity They are uniform: when you know how to use one, you almost know how to use them all You can easily convert from one to another

Uniformity through interfaces Much of the elegance of the Collections Framework arises from the intelligent use of interfaces For example, the Collection interface specifies (among many other operations): boolean add(Object o) boolean isEmpty() boolean remove() int size() Object[] toArray() Iterator iterator()

Vectors The class Vector has been retrofitted to implement the Collection interface Vector supplies add(Object) and iterator() methods (among others) Let’s look at creating a Vector and iterating through the elements

The Iterator interface interface iterator { // java.lang.util boolean hasNext(); // Returns true if the iteration has more // elements. Object next(); // Returns the next element in the // interation. void remove(); // Removes from the underlying collection // the last element returned by the // iterator (optional operation).

Using a Vector Collection numerals = new Vector(); numerals .add("one"); numerals .add("two"); numerals .add("three"); Iterator iter = numerals.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } Results: one two three

Using a TreeSet Collection numerals = new TreeSet(); numerals .add("one"); numerals .add("two"); numerals .add("three"); Iterator iter = numerals.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } Results: one three two

Conversions Vector v = new Vector(numerals); TreeSet ts = new TreeSet(v);

Back to arrays Arrays are not part of the new Collections Framework, but they haven’t been ignored Java 1.2 introduced the new Arrays class, with some useful operations, for example: static void sort(Object[] a) static int binarySearch(Object[] a, Object key) static boolean equals(Object[] a, Object[] a2) static void fill(Object[] a, Object val) static void fill(Object[] a, Object val, int from, int to) static List asList(Object[] a)

What to remember We haven’t really begun to study the Collections framework yet, but— You should learn to use the Iterator interface You should examine and learn more about the Arrays package

The End