Introduction to Collections

Size: px
Start display at page:

Download "Introduction to Collections"

Transcription

1 Module 3 COLLECTIONS Introduction to Collections > A collection sometimes called a container is simply an object that groups multiple elements into a single unit. > Collections are used to store, retrieve, manipulate, and communicate aggregate data

2 What Is a Collections Framework? > A collections framework is a unified architecture for representing and manipulating collections. > All collection frameworks contain the following: Interfaces: Interfaces allow collections to be manipulated independently of the details of their representation Implementations: These are the concrete implementations of the collection interfaces. Algorithms: Methods that perform useful computations on objects that implement collection interfaces. The algorithms are polymorphic: the same method can be used on many different implementations of the appropriate collection interface. Benefits of the Java Collections Framework > The Java Collections Framework provides the following benefits: Reduces programming effort Increases program speed and quality Allows interoperability among unrelated APIs Reduces effort to learn and to use new APIs Reduces effort to design new APIs Fosters software reuse

3 Interfaces > The core collection interfaces encapsulate different types of collections > These interfaces allow collections to be manipulated independently of the details of their representation. > Core collection interfaces are the foundation of the Java Collections Framework. Java Collection Framework

4 Java Collection Framework Interfaces > Note that all the core collection interfaces are generic. public interface Collection<E>... > The <E> syntax tells you that the interface is generic. > When you declare a Collection instance you can and should specify the type of object contained in the collection. > Specifying the type allows the compiler to verify (at compile time) that the type of object you put into the collection is correct, thus reducing errors at runtime.

5 The Collection Interface public interface Collection<E> extends Iterable<E> { // Basic operations int size(); boolean isempty(); boolean contains(object element); boolean add(e element); //optional boolean remove(object element); //optional Iterator<E> iterator(); // Bulk operations boolean containsall(collection<?> c); boolean addall(collection<? extends E> c); //optional boolean removeall(collection<?> c); //optional boolean retainall(collection<?> c); //optional void clear(); //optional The Collection Interface // Array operations Object[] toarray(); <T> T[] toarray(t[] a);

6 The Collection Interface Traversing Collections > There are two ways to traverse collections: for each construct Using Iterators

7 for each Construct > The for each construct allows you to concisely traverse a collection or array using a for loop for (Object o : collection) System.out.println(o); Iterators > An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired. > You get an Iterator for a collection by calling its iterator method. > The following is the Iterator interface. public interface Iterator<E> { boolean hasnext(); E next(); void remove(); //optional

8 Iterator vs for each > Use Iterator instead of the for each construct when you need to: 1. Remove the current element. The for each construct hides the iterator, so you cannot call remove. Therefore, the for each construct is not usable for filtering. 2. Iterate over multiple collections in parallel. Example static void filter(collection<?> c) { for (Iterator<?> it = c.iterator(); it.hasnext(); ) if (!cond(it.next())) it.remove();

9 Removing Elements > The remove method of the Iterator interface removes the element that was returned by the last call to next. > In many situations, that makes sense you need to see the element before you can decide that it is the one that should be removed. > But if you want to remove an element in a particular position, you still need to skip past the element. Iterator<String> it = c.iterator(); it.next(); //skip over the first element it.remove(); // now remove it Removing Elements > If you want to remove two adjacent elements, you cannot simply call it.remove(); it.remove(); // Error! > Instead, you must first call next to jump over the element to be removed. it.remove(); it.next(); it.remove(); // Ok

10 Collection Interface Bulk Operations > Bulk operations perform an operation on an entire Collection. > The following are the bulk operations: containsall returns true if the target Collection contains all of the elements in the specified Collection. addall adds all of the elements in the specified Collection to the target Collection. removeall removes from the target Collection all of its elements that are also contained in the specified Collection Collection Interface Bulk Operations > The following are the bulk operations: retainall removes from the target Collection all its elements that are not also contained in the specified Collection. That is, it retains only those elements in the target Collection that are also contained in the specified Collection. clear removes all elements from the Collection.

11 Collection Interface Bulk Operations > The addall, removeall, and retainall methods all return true if the target Collection was modified in the process of executing the operation. Collection Interface Array Operations > The toarray methods are provided as a bridge between collections and older APIs that expect arrays on input. > The array operations allow the contents of a Collection to be translated into an array. > The simple form with no arguments creates a new array of Object. Object[] a = c.toarray(); > More complex form allows caller to provide an array or to choose the runtime type of the output array. String[] a = c.toarray(new String[0]);

12 Collection Operations > All the interfaces and classes defined in the Java Collections Framework are grouped in the java.util package. > All the concrete classes in the Java Collections Framework implement the Cloneable and Serializable interfaces. > Thus their instances can be cloned and serialized. > Some of the methods in the Collection interface cannot be implemented in the concrete subclass. > In this case, the method would throw java.lang.unsupportedoperationexception. The Set Interface > A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. > The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited. > Set also adds a stronger contract on the behavior of the equals and hashcode operations, allowing Set instances to be compared meaningfully even if their implementation types differ. > Two Set instances are equal if they contain the same elements.

13 The Set Interface public interface Set<E> extends Collection<E> { // Basic operations int size(); boolean isempty(); boolean contains(object element); boolean add(e element); boolean remove(object element); //optional Iterator<E> iterator(); // Bulk operations boolean containsall(collection<?> c); boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); void clear(); // Array Operations Object[] toarray(); <T> T[] toarray(t[] a); The Set Interface

14 The Set Interface > The Java platform contains three general purpose Set implementations: HashSet stores its elements in a hash table, is the best performing implementation; however it makes no guarantees concerning the order of iteration TreeSet stores its elements in a red black tree, orders its elements based on their values; it is substantially slower than HashSet LinkedHashSet spares its clients from the unspecified, generally chaotic ordering provided by HashSet at a cost that is only slightly higher Set Interface Bulk Operations > Bulk operations are particularly well suited to Sets; when applied, they perform standard set algebraic operations. > Suppose s1 and s2 are sets s1.containsall(s2) returns true if s2 is a subset of s1 s1.addall(s2) transforms s1 into the union of s1 and s2. s1.retainall(s2) transforms s1 into the intersection of s1 and s2 s1.removeall(s2) transforms s1 into the (asymmetric) set difference of s1 and s2

15 The List Interface > A List is an ordered Collection. Lists may contain duplicate elements. In addition to the operations inherited from Collection, the List interface includes operations for the following: Positional access manipulates elements based on their numerical position in the list Search searches for a specified object in the list and returns its numerical position Iteration extends Iterator semantics to take advantage of the list's sequential nature Range view performs arbitrary range operations on the list. The List Interface public interface List<E> extends Collection<E> { // Positional access E get(int index); E set(int index, E element); boolean add(e element); void add(int index, E element); E remove(int index); boolean addall(int index, Collection<? extends E> c); // Search int indexof(object o); int lastindexof(object o); // Iteration ListIterator<E> listiterator(); ListIterator<E> listiterator(int index); // Range-view List<E> sublist(int from, int to);

16 The List Interface Comparison to Vector > If you've used Vector, you're already familiar with the general basics of List. > List is an interface, while Vector is a concrete implementation > Consider the following assignment statement. a[i] = a[j].times(a[k]); > The Vector equivalent is: v.setelementat(v.elementat(j).times(v.elementat(k)), i); > The List equivalent is: v.set(i, v.get(j).times(v.get(k)));

17 Comparison to Vector > Consider the following assignment statement. gift[5] = "golden rings"; > The Vector equivalent is: gift.setelementat("golden rings", 5); > The List equivalent is: gift.set(5, "golden rings"); ListIterator<E> public interface ListIterator<E> extends Iterator<E> { boolean hasnext(); E next(); boolean hasprevious(); E previous(); int nextindex(); int previousindex(); void remove(); void set(e e); void add(e e);

18 Iterating backward through a list for (ListIterator<Type> it = list.listiterator(list.size()); it.hasprevious(); ) { Type t = it.previous();... The Cursor > The cursor is always between two elements the one that would be returned by a call to previous and the one that would be returned by a call to next.

19 Queues and Priority Queues > A queue is a first in/first out data structure. > Elements are appended to the end of the queue and are removed from the beginning of the queue. > In a priority queue, elements are assigned priorities. > When accessing elements, the element with the highest priority is removed first. The Queue Interface

20 The PriorityQueue Interface The Map Interface > The Map interface maps keys to the elements. > The keys are like indexes. > In List, the indexes are integer. > In Map, the keys can be any objects.

21 The Map Interface Concrete Map Classes

22 JAVA PUZZLERS ON COLLECTIONS What s in a Name? (Puzzle 57) public class Name { private final String first, last; public Name(String first, String last) { this.first = first; this.last = last; public boolean equals(object o) { if (!(o instanceof Name)) { return false; Name n = (Name) o; return n.first.equals(first) && n.last.equals(last);

23 What s in a Name? public static void main(string[] args) { Set<Name> s = new HashSet<Name>(); s.add(new Name("Mickey", "Mouse")); System.out.println( s.contains(new Name("Mickey", "Mouse")) ); Solution public int hashcode() { return 31 * first.hashcode() + last.hashcode();

24 Making a Hash of It public class Name { private final String first, last; public Name(String first, String last) { this.first = first; this.last = last; public boolean equals(name n) { return n.first.equals(first) && n.last.equals(last); public int hashcode() { return 31 * first.hashcode() + last.hashcode(); Making a Hash of It (Puzzle 58) public static void main(string[] args) { Set<Name> s = new HashSet<Name>(); s.add(new Name("Donald", "Duck")); System.out.println( s.contains(new Name("Donald", "Duck")));

25 What is the Difference? (Puzzle 59) public class Difference { public static void main(string[] args) { int vals[] = { 789, 678, 567, 456, 345, 234, 123, 012 ; Set<Integer> diffs = new HashSet<Integer>(); for (int i = 0; i < vals.length; i++) for (int j = i; j < vals.length; j++) diffs.add(vals[i] - vals[j]); System.out.println(diffs.size()); One Liners (Puzzle 60.A) > Write a method that takes a List of elements and returns a new List containing the same elements in the same order with the second and subsequent occurrences of any duplicate elements removed. > For example, if you pass in a list containing "spam", "sausage", "spam", "spam", "bacon", "spam", "tomato", and "spam", you'll get back a new list containing "spam", "sausage", "bacon", and "tomato".

26 New Game (Puzzle 62) public class NewGame { public static void main(string[] args) { Map<Integer,String> map= new IdentityHashMap<Integer,String>(); map.put(108, "108"); map.put(108, "108"); map.put(549, "549"); map.put(549, "549"); System.err.println(map.size()); More of the Same (Puzzle 63) public class MoreNumbers { private Map<Integer,String> m = new HashMap<Integer,String>(); public void MoreNumbers(){ m.put(108,"108"); m.put(108,"108"); m.put(549,"549"); m.put(549,"549"); public static void main(string[] args) { MoreNumbers morenumbers= new MoreNumbers(); System.err.println(moreNumbers.getSize()); public int getsize(){ return m.size();

27 Concrete Collections ArrayList LinkedList HashSet An indexed sequence that grows and shrinks dynamically An ordered sequence that allows efficient insertions and removal at any location An unordered collection that rejects duplicates TreeSet A sorted set EnumSet A set of enumerated type values LinkedHashSet A set that remembers the order in which elements were inserted PriorityQueue A collection that allows efficient removal of the smallest element Concrete Collections HashMap A data structure that stores key/value associations TreeMap A map in which the keys are sorted EnumMap A map in which the keys belong to an enumerated type LinkedHashMap WeakHashMap IdentityHashMap A map that remembers the order in which entries were added A map with values that can be reclaimed by the garbage collector if they are not used elsewhere A map with keys that are compared by ==, not equals

28 Concrete Collections Concrete Collections

29 Concrete Collections Concrete Collections

30 Concrete Collections

31 Algorithms > The Collections class contains several simple but useful algorithms: static <T extends Comparable<? super T>> T min(collection<t> elements) static <T extends Comparable<? super T>> T max(collection<t> elements) static <T> min(collection<t> elements, Comparator<? super T> c) static <T> max(collection<t> elements, Comparator<? super T> c) Algorithms > static <T> void copy(list<? super T> to, List<T> from) copies all elements from a source list to the same positions in the target list. The target list must be at least as long as the source list. > static <T> void fill(list<? super T> l, T value) sets all positions of a list to the same value. > static <T> boolean addall(collection<? super T> c, T... values) adds all values to the given collection and returns true if the collection changed as a result. > static <T> boolean replaceall(list<t> l, T oldvalue, T newvalue) replaces all elements equal to oldvalue with newvalue.

32 Algorithms > static void swap(list<?> l, int i, int j) swaps the elements at the given offsets. > static void reverse(list<?> l) reverses the order of the elements in a list. For example, reversing the list [t, a, r] yields the list [r, a, t]. This method runs in O(n) time, where n is the length of the list. Algorithms > static int frequency(collection<?> c, Object o) returns the count of elements in c that equal the object o. > boolean disjoint(collection<?> c1, Collection<?> c2) returns true if the collections have no elements in common.

33 COLLECTION BEST PRACTICES Best Practice #1 > Use ArrayLists, HashMap etc as opposed to Vector, Hashtable etc, where possible to avoid any synchronization overhead. > If multiple threads concurrently access a collection and at least one of the threads either adds or deletes an entry into the collection, then the collection must be externally synchronized: Map mymap = Collections.synchronizedMap(myMap); List mylist = Collections.synchronizedList(myList);

34 Best Practice #2 > Set the initial capacity of a collection appropriately (e.g. ArrayList, HashMap etc). > This is because collection classes like ArrayList, HashMap etc. must grow periodically to accommodate new elements. > But if you have a very large array, and you know the size in advance then you can speed things up by setting the initial size appropriately. > HashMaps/Hashtables need to be created with sufficiently large capacity to minimize rehashing (which happens every time the table grows) Best Practice #2 (Con t) > HashMap has two parameters initial capacity load factor > Higher load factor values (default load factor of 0.75 provides a good trade off between performance and space) will reduce the space cost but will increase the lookup cost of mymap.get(&) and mymap.put(&) methods. > When the number of entries in the HashMap exceeds the current capacity loadfactor then the capacity of the HashMap is roughly doubled by calling the rehash function.

35 Best Practice #2 (Con t) > It is also very important not to set the initial capacity too high or load factor too low if iteration performance or reduction in space is important. Best Practice #3 > Program in terms of interface not implementation > For example, you might decide a LinkedList is the best choice for some application, but then later decide ArrayList might be a better choice for performance reason. > Use: List list = new ArrayList(100); > Instead of: ArrayList list = new ArrayList();

36 Best Practice #4 > Return zero length collections or arrays as opposed to returning null > Returning null instead of zero length collection is more error prone, since the programmer writing the calling method might forget to handle a return value of null. Best Practice #5 > Map.containsKey(key) If null keys are allowed in the Map, and null keys are not being used as valid keys in the Map Look for unnecessary call flows that look like: if (map.containskey(key)) value = map.get(key); value will be null if a key is not found via map.get(key) Other use cases using Map methods such as put(key, value) or remove(key) may be eliminated, too.

37 TUNING MEMORY USAGE Java Collections > Each Java Collection has a different level of function, and memory overhead Increasing Functions java.util.hashset java.util.hashmap java.util.hashtable java.util.linkedlist java.util.arraylist Increasing Size > Using the wrong type of collection can incur significant additional memory overhead

38 HashSet public static void main(string[] args){ HashSet<Integer> set= new HashSet<>(); > Implementation of the Set interface > Implementation is a wrapper around a HashMap > Default capacity for HashSet is 16 > Empty size is 144 bytes > Additional 16 bytes overhead for wrapping over HashMap HashMap public static void main(string[] args){ HashMap<Integer> map= new HashMap<>(); > Implementation of the Map interface > Implementation is an array of HashMap$Entry objects > Default capacity is 16 > Empty size is 128 bytes > Overhead is 48 bytes for HashMap Plus (16 + (entries * 4)) byte for array Plus overhead of HashMap$Entry objects

39 LinkedList public static void main(string[] args){ LinkedList list= new LinkedList(); > Implementation of the List interface > Implementation is a linked list of LinkedList$Entry objects > Default capacity is 1 > Empty size is 48 bytes > Overhead is 24 bytes for LinkedList Plus overhead of LinkedList$Entry objects ArrayList public static void main(string[] args){ ArrayList list= new ArrayList(); > Implementation of the List interface > Implementation is a an array of Object > Default capacity is 10 > Empty size is 88 bytes > Overhead is 32 bytes for ArrayList Plus (16 + (entries * 4)) byte for array For a 10,000 entry ArrayList, overhead is ~40K

40 Collections Summary Collection Default Capacity Empty size 10K Overhead HashSet K HashMap K Hashtable K LinkedList K ArrayList K StringBuffer Collections Summary Collection Empty size 10K Overhead Expansion HashSet K x2 HashMap K x2 Hashtable K x2 + 1 LinkedList K + 1 ArrayList 88 40K x1.5 StringBuffer x2

What is the Java Collections Framework?

What is the Java Collections Framework? 1 of 13 What is the Java Collections Framework? To begin with, what is a collection?. I have a collection of comic books. In that collection, I have Tarzan comics, Phantom comics, Superman comics and several

More information

CS Ananda Gunawardena

CS Ananda Gunawardena CS 15-121 Ananda Gunawardena A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data,

More information

9/16/2010 CS Ananda Gunawardena

9/16/2010 CS Ananda Gunawardena CS 15-121 Ananda Gunawardena A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data,

More information

Collections (Collection Framework) Sang Shin Java Technology Architect Sun Microsystems, Inc.

Collections (Collection Framework) Sang Shin Java Technology Architect Sun Microsystems, Inc. Collections (Collection Framework) Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com www.javapassion.com 2 Disclaimer & Acknowledgments Even though Sang Shin is a full-time employee

More information

Class 32: The Java Collections Framework

Class 32: The Java Collections Framework Introduction to Computation and Problem Solving Class 32: The Java Collections Framework Prof. Steven R. Lerman and Dr. V. Judson Harward Goals To introduce you to the data structure classes that come

More information

CONTAİNERS COLLECTİONS

CONTAİNERS COLLECTİONS CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping

More information

Java Collections Framework: Interfaces

Java Collections Framework: Interfaces Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection Interface The List Interface The Iterator Interface The ListIterator

More information

Generics Collection Framework

Generics Collection Framework Generics Collection Framework Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Generics

More information

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering Readings and References Java Collections References» "Collections", Java tutorial» http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Winter 2003 Software Engineering http://www.cs.washington.edu/education/courses/403/03wi/

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces Taking Stock IE170: Algorithms in Systems Engineering: Lecture 7 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 29, 2007 Last Time Practice Some Sorting Algs

More information

Generic classes & the Java Collections Framework. *Really* Reusable Code

Generic classes & the Java Collections Framework. *Really* Reusable Code Generic classes & the Java Collections Framework *Really* Reusable Code First, a bit of history Since Java version 5.0, Java has borrowed a page from C++ and offers a template mechanism, allowing programmers

More information

Collections (Java) Collections Framework

Collections (Java) Collections Framework Collections (Java) https://docs.oracle.com/javase/tutorial/collections/index.html Collection an object that groups multiple elements into a single unit. o store o retrieve o manipulate o communicate o

More information

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1 Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing

More information

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

27/04/2012. Objectives. Collection. Collections Framework. Collection Interface. Collection algorithm. Legacy collection Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"

More information

COURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE

COURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE COURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Inheritance Abstract classes Interfaces instanceof operator Nested classes Enumerations COUSE CONTENT Collections List Map Set Aggregate

More information

Sets and Maps. Part of the Collections Framework

Sets and Maps. Part of the Collections Framework 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 int size( ); boolean isempty( ); boolean contains(object

More information

Lecture 6 Collections

Lecture 6 Collections Lecture 6 Collections Concept A collection is a data structure actually, an object to hold other objects, which let you store and organize objects in useful ways for efficient access Check out the java.util

More information

Java Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering

Java Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering Readings and References Java Collections "Collections", Java tutorial http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Spring 2004 Software Engineering http://www.cs.washington.edu/education/courses/403/04sp/

More information

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of

More information

Vector (Java 2 Platform SE 5.0) Overview Package Class Use Tree Deprecated Index Help

Vector (Java 2 Platform SE 5.0) Overview Package Class Use Tree Deprecated Index Help Overview Package Class Use Tree Deprecated Index Help PREV CLASS NEXT CLASS FRAMES NO FRAMES All Classes SUMMARY: NESTED FIELD CONSTR METHOD DETAIL: FIELD CONSTR METHOD Página 1 de 30 Java TM 2 Platform

More information

Programmieren II. Collections. Alexander Fraser. May 28, (Based on material from T. Bögel)

Programmieren II. Collections. Alexander Fraser. May 28, (Based on material from T. Bögel) Programmieren II Collections Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) May 28, 2014 1 / 46 Outline 1 Recap Paths and Files Exceptions 2 Collections Collection Interfaces

More information

Overview of Java ArrayList, HashTable, HashMap, Hashet,LinkedList

Overview of Java ArrayList, HashTable, HashMap, Hashet,LinkedList Overview of Java ArrayList, HashTable, HashMap, Hashet,LinkedList This article discusses the main classes of Java Collection API. The following figure demonstrates the Java Collection framework. Figure

More information

Important Dates. Game State and Tree. Today s topics. Game Tree and Mini-Max. Games and Mini-Max 3/20/14

Important Dates. Game State and Tree. Today s topics. Game Tree and Mini-Max. Games and Mini-Max 3/20/14 MINI-MAX USING TREES AND THE JAVA COLLECTIONS FRAMEWORK Lecture 16 CS2110 Spring 2014 2 Important Dates. April 10 --- A4 due (Connect 4, minimax, trees) April 15 --- A5 due (Exercises on different topics,

More information

An Interface with Generics

An Interface with Generics Generics CSC207 Software Design Generics An Interface with Generics Generics class foo introduces a class with a type parameter T. introduces a type parameter that is required to be

More information

Java Collection Framework

Java Collection Framework Java Collection Framework Readings Purpose To provide a working knowledge of the Java Collections framework and iterators. Learning Objectives Understand the structure of the Java Collections framework

More information

Collections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)

Collections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock) Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections

More information

Lecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map

Lecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections

More information

Collections Questions

Collections Questions Collections Questions https://www.journaldev.com/1330/java-collections-interview-questions-and-answers https://www.baeldung.com/java-collections-interview-questions https://www.javatpoint.com/java-collections-interview-questions

More information

Abstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures

Abstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures Abstract Data Types (ADTs) Class #08: Linear Data Structures Software Design III (CS 340): M. Allen, 08 Feb. 16 An ADT defines a kind of computational entity: A set of objects, with possible values A set

More information

The Java Collections Framework. Chapters 7.5

The Java Collections Framework. Chapters 7.5 The Java s Framework Chapters 7.5 Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework Outline Introduction to the Java s Framework Iterators Interfaces,

More information

Generics and collections

Generics and collections Generics From JDK 1.5.0 They are similar to C++ templates They allow to eliminate runtime exceptions related to improper casting (ClassCastException) Traditional approach public class Box { private Object

More information

List... NOTE We use List as illustrative example of collections Study the others from textbook!

List... NOTE We use List as illustrative example of collections Study the others from textbook! List... NOTE We use List as illustrative example of collections Study the others from textbook! 25 What is a List? A List is an ordered Collection (sometimes called a sequence) Lists may contain duplicate

More information

Type Parameters: E - the type of elements returned by this iterator Methods Modifier and Type Method and Description

Type Parameters: E - the type of elements returned by this iterator Methods Modifier and Type Method and Description java.lang Interface Iterable Type Parameters: T - the type of elements returned by the iterator Iterator iterator() Returns an iterator over a set of elements of type T. java.util Interface Iterator

More information

Arrays organize each data element as sequential memory cells each accessed by an index. data data data data data data data data

Arrays organize each data element as sequential memory cells each accessed by an index. data data data data data data data data 1 JAVA PROGRAMMERS GUIDE LESSON 1 File: JGuiGuideL1.doc Date Started: July 10, 2000 Last Update: Jan 2, 2002 Status: proof DICTIONARIES, MAPS AND COLLECTIONS We have classes for Sets, Lists and Maps and

More information

The Java Collections Framework and Lists in Java Parts 1 & 2

The Java Collections Framework and Lists in Java Parts 1 & 2 The Java Collections Framework and Lists in Java Parts 1 & 2 Chapter 9 Chapter 6 (6.1-6.2.2) CS 2334 University of Oklahoma Brian F. Veale Groups of Data Data are very important to Software Engineering

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ ABSTRACT DATATYPES 2 Abstract Datatype (ADT)

More information

Lecture 15 Summary 3/11/2009. By the end of this lecture, you will be able to use different types of Collections and Maps in your Java code.

Lecture 15 Summary 3/11/2009. By the end of this lecture, you will be able to use different types of Collections and Maps in your Java code. Lecture 15 Summary Collections Framework Iterable, Collections, Set Map Collections class Comparable and Comparator By the end of this lecture, you will be able to use different types of Collections and

More information

Tha Java Programming Language

Tha Java Programming Language Tha Java Programming Language Kozsik Tamás (2000-2001) kto@elte.hu http://www.elte.hu/~k to/ III. Arrays, collections and other baseclasses Some of the baseclasses Object String StringBuffer Integer, Double,...

More information

17. Java Collections. Organizing Data. Generic List in Java: java.util.list. Type Parameters ( Parameteric Polymorphism ) Data Structures that we know

17. Java Collections. Organizing Data. Generic List in Java: java.util.list. Type Parameters ( Parameteric Polymorphism ) Data Structures that we know Organizing Data Data Structures that we know 17 Java Collections Generic Types, Iterators, Java Collections, Iterators Today: Arrays Fixed-size sequences Strings Sequences of characters Linked Lists (up

More information

Collections Framework: Part 2

Collections Framework: Part 2 Collections Framework: Part 2 Computer Science and Engineering College of Engineering The Ohio State University Lecture 18 Collection Implementations Java SDK provides several implementations of Collection

More information

SUMMARY INTRODUCTION COLLECTIONS FRAMEWORK. Introduction Collections and iterators Linked list Array list Hash set Tree set Maps Collections framework

SUMMARY INTRODUCTION COLLECTIONS FRAMEWORK. Introduction Collections and iterators Linked list Array list Hash set Tree set Maps Collections framework SUMMARY COLLECTIONS FRAMEWORK PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 2016 Introduction Collections and

More information

Algorithms. Produced by. Eamonn de Leastar

Algorithms. Produced by. Eamonn de Leastar Algorithms Produced by Eamonn de Leastar (edeleastar@wit.ie) Collections ± Collections Architecture ± Definition ± Architecture ± Interfaces ± Collection ± List ± Set ± Map ± Iterator ± Implementations

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Generic Programming. *Really* reusable code

Generic Programming. *Really* reusable code Generic Programming *Really* reusable code First, a bit of history Since Java version 5.0, Java has borrowed a page from C++ and offers a template mechanism, allowing programmers to create data structures

More information

Abstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework

Abstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework Announcements Abstract data types (again) PS 5 ready Tutoring schedule updated with more hours Today s topic: The Java Collections Framework Reading: Section 7.5 An ADT is a model of a collection of data

More information

CMSC 202H. Containers and Iterators

CMSC 202H. Containers and Iterators CMSC 202H Containers and Iterators Container Definition A container is a data structure whose purpose is to hold objects. Most languages support several ways to hold objects Arrays are compiler-supported

More information

Charlie Garrod Bogdan Vasilescu

Charlie Garrod Bogdan Vasilescu Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 2: Designing (sub-) systems Java Collec9ons design case study Charlie Garrod Bogdan Vasilescu School of Computer Science 1 Administrivia

More information

Lecture 4. The Java Collections Framework

Lecture 4. The Java Collections Framework Lecture 4. The Java s Framework - 1 - Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework - 2 - Learning Outcomes From this lecture you should

More information

PIC 20A Collections and Data Structures

PIC 20A Collections and Data Structures PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write

More information

Collections and Maps

Collections and Maps Software and Programming I Collections and Maps Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Array Lists Enhanced for Loop ArrayList and LinkedList Collection Interface Sets and

More information

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University C O P Y R I G H T S 2 0 1 5 E O M, H Y E O N S A N G A L L R I G H T S R E S E R V E D - Containers - About Containers

More information

[Ref: Core Java Chp 13, Intro to Java Programming [Liang] Chp 22, Absolute Java Chp 16, docs.oracle.com/javase/tutorial/collections/toc.

[Ref: Core Java Chp 13, Intro to Java Programming [Liang] Chp 22, Absolute Java Chp 16, docs.oracle.com/javase/tutorial/collections/toc. Contents Topic 08 - Collections I. Introduction - Java Collection Hierarchy II. Choosing/using collections III. Collection and Iterator IV. Methods of Collection V. Concrete classes VI. Implementation

More information

Collections. The Java Collections Framework. The Interfaces

Collections. The Java Collections Framework. The Interfaces Collections A collection (sometimes called a container) is an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data, and to transmit data

More information

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION

More information

ArrayList. Introduction. java.util.arraylist

ArrayList. Introduction. java.util.arraylist ArrayList Introduction In this article from my free Java 8 course, I will be giving you a basic overview of the Java class java.util.arraylist. I will first explain the meaning of size and capacity of

More information

Java Collections Framework reloaded

Java Collections Framework reloaded Java Collections Framework reloaded October 1, 2004 Java Collections - 2004-10-01 p. 1/23 Outline Interfaces Implementations Ordering Java 1.5 Java Collections - 2004-10-01 p. 2/23 Components Interfaces:

More information

Java and C# in Depth

Java and C# in Depth Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 4 Chair of Software Engineering Don t forget to form project groups by tomorrow (March

More information

Framework in Java 5. DAAD project Joint Course on OOP using Java

Framework in Java 5. DAAD project Joint Course on OOP using Java Topic XXX Collections Framework in Java 5 DAAD project Joint Course on OOP using Java Humboldt University Berlin, University of Novi Sad, Polytehnica University of Timisoara, University of Plovdiv, University

More information

Recap. List Types. List Functionality. ListIterator. Adapter Design Pattern. Department of Computer Science 1

Recap. List Types. List Functionality. ListIterator. Adapter Design Pattern. Department of Computer Science 1 COMP209 Object Oriented Programming Container Classes 3 Mark Hall List Functionality Types List Iterator Adapter design pattern Adapting a LinkedList to a Stack/Queue Map Functionality Hashing Performance

More information

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No

More information

EXAMINATIONS 2016 TRIMESTER 2

EXAMINATIONS 2016 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

Fundamental language mechanisms

Fundamental language mechanisms Java Fundamentals Fundamental language mechanisms The exception mechanism What are exceptions? Exceptions are exceptional events in the execution of a program Depending on how grave the event is, the program

More information

List ADT. Announcements. The List interface. Implementing the List ADT

List ADT. Announcements. The List interface. Implementing the List ADT Announcements Tutoring schedule revised Today s topic: ArrayList implementation Reading: Section 7.2 Break around 11:45am List ADT A list is defined as a finite ordered sequence of data items known as

More information

Collections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Collections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff Collections by Vlad Costel Ungureanu for Learn Stuff Collections 2 Collections Operations Add objects to the collection Remove objects from the collection Find out if an object (or group of objects) is

More information

Computer Science II (Spring )

Computer Science II (Spring ) Computer Science II 4003-232-01 (Spring 2007-2008) Week 5: Generics, Java Collection Framework Richard Zanibbi Rochester Institute of Technology Generic Types in Java (Ch. 21 in Liang) What are Generic

More information

Le L c e t c ur u e e 8 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Collections

Le L c e t c ur u e e 8 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Collections Course Name: Advanced Java Lecture 8 Topics to be covered Collections Introduction A collection, sometimes called a container, is simply an object that groups multiple elements into a single unit. Collections

More information

COMP6700/2140 Abstract Data Types: Queue, Set, Map

COMP6700/2140 Abstract Data Types: Queue, Set, Map COMP6700/2140 Abstract Data Types: Queue, Set, Map Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU 19 April 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140

More information

From Java Code to Java Heap Understanding the Memory Usage of Your Application

From Java Code to Java Heap Understanding the Memory Usage of Your Application Chris Bailey IBM Java Service Architect 3 rd October 2012 From Java Code to Java Heap Understanding the Memory Usage of Your Application 2012 IBM Corporation Important Disclaimers THE INFORMATION CONTAINED

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 6. The Master Theorem. Some More Examples...

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 6. The Master Theorem. Some More Examples... Taking Stock IE170: Algorithms in Systems Engineering: Lecture 6 Jeff Linderoth Last Time Divide-and-Conquer The Master-Theorem When the World Will End Department of Industrial and Systems Engineering

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net Sorting Tree Balancing A sorted tree is balanced iff for each node holds: Math.abs(size(node.left)

More information

EXAMINATIONS 2017 TRIMESTER 2

EXAMINATIONS 2017 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2017 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

Topic 10: The Java Collections Framework (and Iterators)

Topic 10: The Java Collections Framework (and Iterators) Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of

More information

Interfaces, collections and comparisons

Interfaces, collections and comparisons תכנות מונחה עצמים תרגול מספר 4 Interfaces, collections and comparisons Interfaces Overview Overview O Interface defines behavior. Overview O Interface defines behavior. O The interface includes: O Name

More information

Java Collections Framework

Java Collections Framework Java Collections Framework Introduction In this article from my free Java 8 course, you will be given a high-level introduction of the Java Collections Framework (JCF). The term Collection has several

More information

The Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss

The Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss The Collections API Mark Allen Weiss Lecture Objectives To learn how to use the Collections package in Java 1.2. To illustrate features of Java that help (and hurt) the design of the Collections API. Tuesday,

More information

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel)

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel) Programmieren II Polymorphism Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) June 4, 2014 1 / 50 Outline 1 Recap - Collections 2 Advanced OOP: Polymorphism Polymorphism

More information

EECS 2011 M: Fundamentals of Data Structures

EECS 2011 M: Fundamentals of Data Structures EECS 2011 M: Fundamentals of Data Structures Suprakash Datta Office: LAS 3043 Course page: http://www.eecs.yorku.ca/course/2011m Also on Moodle S. Datta (York Univ.) EECS 2011 W18 1 / 19 Iterators and

More information

CIS 265 Exam 2 First Name Last Name

CIS 265 Exam 2 First Name Last Name CIS 265 Exam 2 First Name Last Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the data types below does not allow duplicates? 1)

More information

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming Frameworks 1 Framework Set of cooperating classes/interfaces Structure essential mechanisms of a problem domain Programmer can extend framework classes, creating new functionality Example: Swing package

More information

Practical Session 3 Java Collections

Practical Session 3 Java Collections Practical Session 3 Java Collections 1 Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack Maps The Collections class Wrapper classes 2 Collection

More information

CMSC 202. Containers

CMSC 202. Containers CMSC 202 Containers Container Definition A container is a data structure whose purpose is to hold objects. Most languages support several ways to hold objects. Arrays are compiler-supported containers.

More information

Principles of Software Construction: Objects, Design and Concurrency. More design patterns and Java Collections. toad

Principles of Software Construction: Objects, Design and Concurrency. More design patterns and Java Collections. toad Principles of Software Construction: Objects, Design and Concurrency 15-214 toad More design patterns and Java Collections Spring 2013 Christian Kästner Charlie Garrod School of Computer Science 2012-13

More information

Beside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions.

Beside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions. Collections Beside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions. Map: Indexes collections by arbitrary keys. HashSet import java.util.hashset;

More information

Lecture 6: ArrayList Implementation

Lecture 6: ArrayList Implementation Lecture 6: ArrayList Implementation CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Programming Assignment Weak AI/Natural Language Processing: Generate text by building frequency lists based

More information

Java Collections. Wrapper classes. Wrapper classes

Java Collections. Wrapper classes. Wrapper classes Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being

More information

Java Collections. Engi Hafez Seliem

Java Collections. Engi Hafez Seliem Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J2

EPITA Première Année Cycle Ingénieur. Atelier Java - J2 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Plan 1 2 A Solution: Relation to ML Polymorphism 3 What are Collections Collection Core Interface Specific Collection

More information

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 36. Collections Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Arrays Class Interface Collection and Class Collections ArrayList Class Generics LinkedList Class Collections Algorithms

More information

Some examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani. The Collection Framework

Some examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani. The Collection Framework Some examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani The Collection Framework Collection: an aggregate that can hold a varying number of elements Interface:

More information

Java Language Features

Java Language Features Java Language Features References: Object-Oriented Development Using Java, Xiaoping Jia Internet Course notes by E.Burris Computing Fundamentals with Java, by Rick Mercer Beginning Java Objects - From

More information

Pieter van den Hombergh Richard van den Ham. February 8, 2018

Pieter van den Hombergh Richard van den Ham. February 8, 2018 Pieter van den Hombergh Richard van den Ham Fontys Hogeschool voor Techniek en Logistiek February 8, 2018 /FHTenL February 8, 2018 1/16 Collection Zoo The basic collections, well known in programming s

More information

Generic Collections CSC Spring 2019 Howard Rosenthal

Generic Collections CSC Spring 2019 Howard Rosenthal Generic Collections CSC 295-01 Spring 2019 Howard Rosenthal Course References Materials for this course have utilized materials in the following documents. Additional materials taken from web sites will

More information

Lists. The List ADT. Reading: Textbook Sections

Lists. The List ADT. Reading: Textbook Sections Lists The List ADT Reading: Textbook Sections 3.1 3.5 List ADT A list is a dynamic ordered tuple of homogeneous elements A o, A 1, A 2,, A N-1 where A i is the i-th element of the list The position of

More information

Collection Interfaces

Collection Interfaces CJ7V2.book Page 85 Wednesday, October 27, 2004 2:32 PM 2 Collections COLLECTION INTERFACES CONCRETE COLLECTIONS THE COLLECTIONS FRAMEWORK ALGORITHMS LEGACY COLLECTIONS Object-oriented programming (OOP)

More information

13 A: External Algorithms II; Disjoint Sets; Java API Support

13 A: External Algorithms II; Disjoint Sets; Java API Support 13 A: External Algorithms II; ; Java API Support Martin Henz April 15, 2009 Generated on Friday 13 17 A: th External April, 2009, Algorithms 12:37 II; ; Java API Support 1 1 External Sorting 2 3 4 13 A:

More information

CSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4

CSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Related classes Consider classes for

More information

Agenda. Inner classes and implementation of ArrayList Nested classes and inner classes The AbstractCollection class Implementation of ArrayList

Agenda. Inner classes and implementation of ArrayList Nested classes and inner classes The AbstractCollection class Implementation of ArrayList Implementations I 1 Agenda Inner classes and implementation of ArrayList Nested classes and inner classes The AbstractCollection class Implementation of ArrayList Stack and queues Array-based implementations

More information

A simple map: Hashtable

A simple map: Hashtable Using Maps A simple map: Hashtable To create a Hashtable, use: import java.util.*; Hashtable table = new Hashtable(); To put things into a Hashtable, use: table.put(key, value); To retrieve a value from

More information

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. June 8, 2017

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. June 8, 2017 Pieter van den Hombergh Thijs Dorssers Stefan Sobek Fontys Hogeschool voor Techniek en Logistiek June 8, 2017 /FHTenL June 8, 2017 1/19 Collection Zoo The basic collections, well known in programming s

More information

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding

More information