UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support.

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.
Collections. What is the Collections framework?  Collections framework provides two things: –implementations of common high-level data structures: e.g.
Collections CS3250. Sources  Slides by Professor Chuck Allison  Core Java, by Cay S. Horstmann and Gary Cornell  The Java Tutorial 
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 7 Object Oriented Programming in Java Advanced Topics Collection.
Using Maps. A simple map: Hashtable To create a Hashtable, use: import java.util.*; Hashtable table = new Hashtable(); To put things into a Hashtable,
15-Jun-15 Lists in Java Part of the Collections Framework.
Professor Evan Korth (adapted from Sun’s collections documentation)
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  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.
1 The Collection Interface public interface Collection extends Iterable { boolean add(E e); boolean addAll(Collection c); void clear(); boolean contains(Object.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
12-Jul-15 Lists in Java Part of the Collections Framework.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
1 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
„Generics and collections”. Generics and collections Generics From JDK They are similar to C++ templates They allow to eliminate runtime exceptions.
The Java Collections Package C. DeJong Fall 2001.
Java's Collection Framework
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.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
1.0tCopyright © 1998 Purple Technology, Inc. 1 Java Collections Framework Authored by Alex Chaffee Copyright © 1998 Purple Technology, Inc. All rights.
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
The Java Collections Framework Based on
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Java 2 Collections Bartosz Walter Software Engineering II.
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
©SoftMoore ConsultingSlide 1 Java Collections Framework.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
CS Ananda Gunawardena.  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Set and Map IS 313, Skeletons  Useful coding patterns  Should understand how and why they work how to use  possible quiz material.
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
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.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
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.
Data Structures I Collection, List, ArrayList, LinkedList, Iterator, ListNode.
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.
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
Java Collections CHAPTER 3-February-2003
Java Collections OOP tirgul No
Fundamental of Java Programming
Programming & Data Structures
Advanced Java FDP on 12th June, 2017.
Introduction to Collections
Programming in Java Lecture 11: ArrayList
Lecture 6: Collections.
Introduction to Collections
Part of the Collections Framework
Collections in Java The objectives of this lecture are:
Introduction to Collections
Collections Framework
Introduction to Collections
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Hashing in java.util
Part of the Collections Framework
Java Generics & Iterators
Presentation transcript:

UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support [Java 2: The Complete Reference: Chapter 15] [Deitel: Chapters 22, 23, 24] Mon. 10/23/00

Homework Status 1 Fri, 9/8 9/15, 9/18 2Fri, 9/15 Fri, 9/22 3Fri, 9/22 Fri, 9/29 4Fri, 10/6Fri, 10/13 5Fri, 10/13Fri, 10/20 6Fri, 10/20 Fri, 10/27 HW# Assigned Due Graded Submitted Pending

Overview ä Collections Framework ä Iterator Interface ä Comparator Interface ä Map Interface ä Collection Algorithms

Java Collections Framework ä Similar to C++ Standard Template Library (STL) ä C++ container -> Java collection ä Unifies previous Java data structure classes ä e.g.: Vector, Stack, Hashtable ä Goals: high-performance, interoperability, extensibility ä Algorithms: operate on collections ä provided as static class methods ä Iterator interface: to step through a collection ä Collection view of a Map (stores key/value pairs) Manipulates Objects

“Core” Collection Interfaces Collection List Set SortedSet group of objects ordered list of objects unordered group of unique objects ordered group of unique objects [in java.util]

boolean add(Object obj) boolean addAll(Collection c) void clear( ) boolean contains(Object obj) boolean containsAll(Collection c) boolean equals(Object obj) int hashCode( ) Collection Interface Methods boolean isEmpty( ) Iterator iterator( ) boolean remove(Object obj) boolean removeAll(Collection c) boolean retainAll(Collection c) int size( ) Object[ ] toArray( ) Object[ ] toArray(Object array[ ]) Exceptional Notes: UnsupportedOperationExceptionUnsupportedOperationException ClassCastExceptionClassCastException

void add(int index, Object obj) boolean addAll(int index, Collection c) Object get(int index) int indexOf(Object obj) int lastIndexOf(Object obj) List Interface Methods ListIterator listIterator( ) ListIterator listIterator(int index) Object remove(int index) Object set(int index, Object obj) List subList(int start, int end) Position in list uses 0-based index.

Comparator comparator( ) Object first( ) SortedSet headSet(Object end) Object last( ) SortedSet subSet(Object start, Object end) SortedSet tailSet(Object start) Set & Sorted Set Interfaces Set does not define any additional methods of its own. SortedSet Methods

Collection Classes Collection ListSet SortedSet Note: Here we use to denote “implements” AbstractCollection AbstractList AbstractSequentialList LinkedList [in java.util] ArrayList AbstractSet HashSetTreeSet stores values in sorted order

ArrayList Class ä Variable-length array of object references ä legacy class Vector also supports dynamic array sizing ä Constructors ä ArrayList( ) ArrayList(Collection c) ä ArrayList(int capacity)

LinkedList Class ä Constructors ä LinkedList( ) ä LinkedList(Collection c) ä Other Methods: ä void addFirst(Object obj) ä void addLast(Object obj) ä Object getFirst( ) ä Object getLast( ) ä Object removeFirst( ) ä Object removeLast( )

HashSet Class ä Constructors ä HashSet( ) ä HashSet(Collection c) ä HashSet(int capacity) ä HashSet(int capacity, float fillRatio)

TreeSet Class ä Constructors ä TreeSet( ) ä TreeSet(Collection c) ä TreeSet(Comparator comp) ä TreeSet(SortedSet ss) stores values in sorted order

Iterator Interface Iterator ListIterator cycle through collection get/remove Objects bi-directional traversal bi-directional traversal modify Objects modify Objects boolean hasNext( ) Object next( ) void remove( ) boolean add(Object obj) boolean hasNext( ) boolean hasPrevious( ) Object next( ) int nextIndex( ) Object previous( ) int previousIndex( ) void remove( ) void set(Object obj)

Comparator Interface Comparator defines meaning of “sorted order” int compare( Object obj1, Object obj2) boolean equals(Object obj)

Map Interface ä Map: Object that stores key/value pairs ä stores associations ä keys, values are Objects ä key is unique (value need not be unique) Map SortedMap stores key/value pairs Map.Entry represents a key/value pair stores key/value pairs in ascending (key) order

void clear( ) boolean containsKey(Object k) boolean containsValue(Object v) Set entrySet( ) boolean equals(Object obj) Object get(Object k) int hashCode( ) Map Interface Methods Exceptional Notes: UnsupportedOperationExceptionUnsupportedOperationException NoSuchElementExceptionNoSuchElementException ClassCastExceptionClassCastException NullPointerExceptionNullPointerException boolean isEmpty( ) Set keySet( ) Object put(Object k, Object v) void putAll(Map m) Object remove(Object k) int size( ) Collection values( )

Comparator comparator( ) Object firstKey( ) SortedMap headMap(Object end) Object lastKey( ) SortedMap subMap(Object start, Object end) SortedMap tailMap(Object start) SortedMap Interface Methods Exceptional Notes: NoSuchElementExceptionNoSuchElementException ClassCastExceptionClassCastException NullPointerExceptionNullPointerException

boolean equals(Object obj) Object getKey( ) Object getValue( ) int hashCode( ) Object setValue(Object v) Map.Entry Interface Methods

Map Classes Note: Here we use to denote “implements” [in java.util] Map AbstractMap TreeMapHashMap WeakHashMap garbage collection for unused keys stores values in sorted order

HashMap Class ä Constructors ä HashMap( ) ä HashMap(Map m) ä HashMap(int capacity) ä HashMap(int capacity, float fillRatio) Note: Does not guarantee order of items!

TreeMap Class ä Constructors ä TreeMap( ) ä TreeMap(Comparator comp) ä TreeMap(Map m) ä TreeMap(SortedMap sm) Allows rapid retrieval stores values in sorted order

Collection Algorithms static int binarySearch(List list, Object value, Comparator c) static int binarySearch(List list, Object value) static void copy(List list1, List list2) static Enumeration enumeration(Collection c) static void fill(List list, Object obj) static Object max(Collection c, Comparator comp) static Object max(Collection c) static Object min(Collection c, Comparator comp) static Object min(Collection c) static List nCopies(int num, Object obj) static void reverse( List list) static Comparator reverseOrder( )

Collection Algorithms (continued) static void shuffle(List list, Random r) static void shuffle(List list) static Set singleton(Object obj) static void sort(List list, Comparator comp) static void sort(List list) static Collection synchronizedCollection(Collection c) static List synchronizedList(List list) static Map synchronizedMap(Map m) static Set synchronizedSet(Set s) static SortedMap synchronizedSortedMap(SortedMap sm) static SortedSet synchronizedSortedSet(SortedSet ss)

Collection Algorithms (continued) Static Collection unmodifiableCollection(Collection c) Static List unmodifiableList(List list) Static Map unmodifiableMap(Map m) Static Set unmodifiableSet(Set s) Static SortedMap unmodifiableSortedMap(SortedMap sm) Static SortedSet unmodifiableSortedSet(SortedSet ss)