Generic Collections CSC Spring 2019 Howard Rosenthal

Size: px
Start display at page:

Download "Generic Collections CSC Spring 2019 Howard Rosenthal"

Transcription

1 Generic Collections CSC Spring 2019 Howard Rosenthal

2 Course References Materials for this course have utilized materials in the following documents. Additional materials taken from web sites will be referenced when utilized Anderson, Julie and Franceschi Herve, Java Illuminated 5 TH Edition,, Jones and Bartlett, Bravaco, Ralph and Simonson, Shai, Java programming From The Ground Up, McGraw Hill, Deitel, Paul and Deitel, Harvey, Java, How To Program, Early Objects, Eleventh Edition, Pearson Publishing, Gaddis, Tony, Starting Out With Objects From Control Structures Through Objects, Pearson Publishing, Version 7, Horstmann, Cay, Core Java For The Impatient, Addison Wesley- Pearson Education, Schmuller, Joseph, Teach Yourself UML In 24 Hours Second Edition, SAMS Publishing, Urma, Raoul-Gabriel, Fusco, Mario and Mycroft, Alan, Java 8 in Action: Lambdas, Streams, and Functional-Style Programming, Manning Publishing, Wirfs-Brock, Rebecca, Wilkerson, Brian and Wiener, Laura, Designing Object- Oriented Software, Prentice Hall,

3 Lesson Goals Learn what Collections are Use class Arrays for array manipulation Briefly review wrapper classes, boxing and unboxing Learn to use pre-built generic data structures Use algorithms of the Collections class to process collections Learn about iterators 3

4 4

5 The Collections Framework The collections framework is a unified architecture for representing and manipulating collections, enabling them to be manipulated independently of the details of their representation. It contains prebuilt generic data structures It reduces programming effort while increasing performance. It enables interoperability among unrelated APIs, reduces effort in designing and learning new APIs, and fosters software reuse. It allows interoperability between APIs The framework is based on more than a dozen collection interfaces. It includes implementations of these interfaces and algorithms to manipulate them. The interface Collection contains bulk operations for adding, clearing and comparing objects in a collection. This includes adding a list of elements, or even a whole Collection, to a Collection Don t confuse the Collection interface with the Collections class 5

6 Describing The Collections Class And Collections Objects This Collections class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends. The methods of this class all throw a NullPointerException if the collections or class objects provided to them are null. The "destructive" algorithms contained in this class, that is, the algorithms that modify the collection on which they operate, are specified to throw UnsupportedOperationException if the collection does not support the appropriate mutation primitive(s), such as the set method. A collection is a data structure actually an object that can hold references to other objects Usually collections contain references to objects of any type that has an is-a relationship In other words it takes advantage of polymorphism i.e an ArrayList of a certain type can have as member any subclass of that type Collections cannot manipulate variables of primitive data This is why we use wrapper classes for the primitive variables, taking advantage of autoboxing and unboxing, when needing to use a Collection class (i.e. ArrayList) with objects See IntegersInArrayList.java and CharacterArrayListExample.java See 6

7 The Java Collection Framework Hierarchy For The Collection interface 7

8 Polymorphism Example With ArrayList In the example below assume we create the ArrayList: ArrayList <Auto> autotlist = new ArrayList<Auto>(); Then not only Auto objects, but Ford, Honda, Volvo, Civic, Accord and Pilot objects, etc. can be added to the ArrayList autolist Remember that if you retrieve an object from autolist you may need to cast downward to exact type in order to access it s data and methods Auto Ford Honda Volvo Civic Accord Pilot 8

9 Some Collections Framework Interfaces The collections framework classes and interfaces are all found in the java.util package 9

10 Using The Iterator And iterator() Method An Introduction Often you wish to access the elements of an ArrayList one by one, in order You could write a counting loop You can use an Iterator object. The Interface Collection provides a method that returns an Iterator object, which allows a program to walk through the collection and remove elements from the collection during the iteration. To get an Iterator object, use the iterator method of ArrayList: Iterator<E> iterator() // Returns an iterator i.e. Iterator<String> iter = names.iterator(); //creates an Iterator object ArrayList implements the Iterable interface (to be discussed later). iterator() is the only method in this interface An iterator object is used to visit the elements of a list one by one It visits only the cells that have data (so you don't need to worry about going past the end of data) This is more convenient than writing a loop 10

11 Iterator Methods An iterator implements the Iterator<E> interface, which has the following methods: boolean hasnext() // Returns true if not all elements have been visited E next() // Returns the next element of the list, a reference to type E void remove() // Remove from the list the element just returned by next() You need to import the Iterator class: import java.util.iterator; Note: If a collection is modified by one of its methods after an iterator is created for that collection, the iterator becomes invalid Any operation performed with the iterator fails immediately and throws an exception. This is called fast-fail Fast-fail iterators help ensure that a modifiable collection is not manipulated by two or more threads at the same time. See ArrayListExampleIterator.java 11

12 Using The Enhanced For Loop With The ArrayList Class The enhanced for loop (sometimes called a "for each" loop) can be used with any class that implement the Iterable interface, such as ArrayList for (ClassName currentobject: ArrayListName) { Process currentobject } The program does the same thing as we showed with the Iterator The enhanced for loop accesses the String references in names and assigns them one-by-one to currentobject With an enhanced for loop there is no danger an index will go out of bounds The enhanced for loop only visits those cells that are not empty, beginning with cell zero Since an ArrayList never has gaps between cells, all occupied cells are visited See ArrayListExampleIterator.java 12

13 13

14 Understanding Lists (1) A List (sometimes called a sequence) is an ordered Collection that can contain duplicate elements. List indices are zero based. In addition to the methods inherited from Collection, List provides methods for: Manipulating elements via their indices Manipulating a specified range of elements Searching for elements and obtaining a ListIterator to access the elements. Interface List is implemented by several classes, including ArrayList, LinkedList and Vector. (We discuss LinkedList later) Autoboxing occurs when you add primitive-type values to objects of these classes, because they store only references to objects. See 14

15 Understanding Lists (2) Class ArrayList and Vector are resizable-array implementations of List. Inserting an element between existing elements of an ArrayList or Vector is an inefficient operation. A LinkedList enables efficient insertion (or removal) of elements in the middle of a collection, but is much less efficient than an ArrayList for jumping to a specific element in the collection. We discuss the architecture of linked lists later. The primary difference between ArrayList and Vector is that operations on Vectors are synchronized by default, whereas those on ArrayLists are not. Unsynchronized collections provide better performance than synchronized ones. For this reason, ArrayList is typically preferred over Vector in programs that do not share a collection among threads. 15

16 ArrayList and Iterator List method add adds an item to the end of a list. List method size returns the number of elements. List method get retrieves an individual element s value from the specified index. Collection method iterator gets an Iterator for a Collection. Iterator- method hasnext determines whether there are more elements to iterate through. Returns true if another element exists and false otherwise. Iterator method next obtains a reference to the next element. Collection method contains determine whether a Collection contains a specified element. Iterator method remove removes the current element from a Collection. Note: We refer to each ArrayList in this example. This would for instance allow us to substiture LinkedList for ArrayList if we needed to. Same with the way we implement removecolors method See CollectionTest.java 16

17 The LinkedList An Overview Linked Lists are linear data structures where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using references to addresses. Each element is known as a node. Due to the dynamicity and ease of insertions and deletions, they are preferred over the arrays. With an ArrayList, insertions and deletions require rewriting all elements after the insertion It also has few disadvantages like the nodes cannot be accessed directly instead we need to start from the head and follow through the link to reach to a node we wish to access. To store the elements in a linked list we use a doubly linked list which provides a linear data structure and also used to inherit an abstract class and implement list and deque interfaces. In Java, LinkedList class implements the list interface. The LinkedList class also consists of various constructors and methods like other java collections. We demonstrate some of these in LinkedListTest.java See 17

18 Inserting A Node In a Doubly Linked List The dotted lines shows what happens when you insert Leah between Joshua and Miriam 18

19 Array vs. Linked List The LinkedList class in java is doubly linked This means it has a reference to the predecessor as well as the successor 19

20 20

21 Collections class Implements A Number Of Useful Static Methods Method Description sort reverse shuffle fill copy min max binarysearch addall frequency disjoint Sorts the elements of a Collection in an input list See CollectionSorting.java or CollectionSorting1.java or (Time.java, TimeComparator.java and SortingTime.java) Reverses all the elements in a Collection See CollectionSorting1.java Random shuffling of the elements of a Collection (very good in card simulations) See ShuffleExample.java or (Card.java, DeckOfCards.java and CardShuffleTester.java Sets every element in the Collection to refer to the given argument (see AlgorithmsForCollections.java) Copies the references from one Collection into another List. The destination List must be at least as long as the source List; otherwise, an IndexOutOfBoundsException occurs. (see AlgorithmsForCollections.java) Returns the smallest element in a Collection, based on the elements comparator (i.e must implement the Comparable interface) Returns the largest element in a Collection, based on the elements comparator (see AlgorithmsForCollections.java) Locate an item in a sorted Collection using binary search See BinarySearchTest.java Appends all the elements in an array to a Collection. See AlgorithmsForMoreCollectionMethods.java Calculates how many Collection elements are equal to the specified element. See AlgorithmsForMoreCollectionMethods.java Returns true if two Collections have no elements in common otherwise false. See AlgorithmsForMoreCollectionMethods.java 21

22 The sort Method Method sort sorts the elements of a List The elements must implement the Comparable interface. The order is determined by the natural order of the elements type as implemented by a compareto method. Method compareto is declared in interface Comparable and is sometimes called the natural comparison method. The sort call may specify as a second argument a Comparator object that determines an alternative ordering of the elements. Note: in several of the programs we use the Arrays method aslist, which allows you to view an array as a List Collection. This List view allows you to manipulate the array as if it were a List. Useful for adding elements in the array to a List, and for sorting. 22

23 Using Comparator in Sorting The custom Comparator class, named TimeComparator, that implements interface Comparator to compare two Time objects. Class Time represents times with hours, minutes and seconds. Class TimeComparator implements interface Comparator, a generic type that takes one type argument. A class that implements Comparator must declare a compare method that receives two arguments and returns a negative integer if the first argument is less than the second, 0 if the arguments are equal or a positive integer if the first argument is greater than the second. See Time.java, TimeComparator.java and SortingTime.java 23

24 Using the binarysearch Method static Collections method binarysearch locates an object in a List. If the object is found, its index is returned. If the object is not found, binarysearch returns a negative value. Method binarysearch determines this negative value by first calculating the insertion point and making its sign negative. Then, binarysearch subtracts 1 from the insertion point to obtain the return value, which guarantees that method binarysearch returns positive numbers (>= 0) if and only if the object is found. Binary search can only be used after sorting the list 24

25 25

26 The Queue Interface - Overview A Queue is a First In First Out (FIFO) data structure. It models a queue in real-life. Yes, the one that you might have seen in front of a movie theater, a shopping mall, a metro, or a bus. Just like queues in real life, new elements in a Queue data structure are added at the back and removed from the front. A Queue can be visualized as shown in the figure below. 26

27 The Queue interface The Queue interface is available in java.util package and extends the Collection interface. It is used to hold the elements about to be processed and provides various operations like the insertion, removal etc. It is an ordered list of objects with its use limited to insert elements at the end of the list and deleting elements from the start of list i.e. it follows the FIFO or the First-In-First-Out principle. Being an interface the queue needs a concrete class for the declaration and the most common classes are the PriorityQueue and LinkedList in Java. It is to be noted that both the implementations are not thread safe. PriorityBlockingQueue is one alternative implementation if thread safe implementation is needed. Important characteristics of Queue are: The Queue is used to insert elements at the end of the queue and removes from the beginning of the queue. It follows FIFO concept. The Java Queue supports all methods of Collection interface including insertion, deletion etc. LinkedList, ArrayBlockingQueue and PriorityQueue are the most frequently used implementations. If any null operation is performed on BlockingQueues, NullPointerException is thrown. BlockingQueues have thread-safe implementations. The Queues which are available in java.util package are Unbounded Queues The Queues which are available in java.util.concurrent package are the Bounded Queues. All Queues except the Deques supports insertion and removal at the tail and head of the queue respectively. The Deques support element insertion and removal at both ends. 27

28 The Queue interface Inheritance Hierarchy 28

29 The Queue interface Methods Methods of the Queue interface include: add()- This method is used to add elements at the tail of queue. More specifically, at the last of LinkedList if it is used, or according to the priority in case of priority queue implementation. peek()- This method is used to view the head of queue without removing it. It returns Null if the queue is empty. element()- This method is similar to peek(). It throws NoSuchElementException when the queue is empty. remove()- This method removes and returns the head of the queue. It throws NoSuchElementException when the queue is empty. poll()- This method removes and returns the head of the queue. It returns null if the queue is empty. size()- This method return the no. of elements in the queue. See programs QueueExample.java See 29

30 The PriorityQueue class Overview A priority queue in Java is a special type of queue wherein all the elements are ordered as per their natural ordering or based on a custom Comparator supplied at the time of creation. The front of the priority queue contains the least element according to the specified ordering, and the rear of the priority queue contains the greatest element. When you remove an element from the priority queue, the least element according to the specified ordering is removed first. 30

31 The PriorityQueue class A PriorityQueue is used when the objects are supposed to be processed based on the priority. It is known that a queue follows First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority, that s when the PriorityQueue comes into play. The PriorityQueue is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. Important points on Priority Queue are as follows: PriorityQueue doesn t permit NULL pointers. We can t create PriorityQueue of Objects that are non-comparable PriorityQueue are unbound queues. The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue. It inherits methods from AbstractQueue, AbstractCollection, Collection and Object class. 31

32 The PriorityQueue class Inheritance Hierarchy 32

33 PriorityQueue class Constructors PriorityQueue() Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering. PriorityQueue(Collection c) Creates a PriorityQueue containing the elements in the specified collection. PriorityQueue(int initialcapacity) Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering. PriorityQueue(int initialcapacity, Comparator comparator) Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator. PriorityQueue(PriorityQueue c) Creates a PriorityQueue containing the elements in the specified priority queue. PriorityQueue(SortedSet c) Creates a PriorityQueue containing the elements in the specified sorted set. See CreatePriorityQueue.java, CreatePriorityQueueStringExample.java, PriorityQueueCustomComparatorExample.java, see (PriorityQueueUserDefinedObjectExample.java, Employee.java), PriorityQueueExample.java 33

34 34

35 Set Overview A Set is an unordered Collection of unique elements, that is no duplicates. The collections framework contains several Set implementations, including HashSet, LinkedHashSet and TreeSet. HashSet stores its elements in a hash table, and TreeSet stores its elements in a tree. The collections framework also includes the SortedSet interface (which extends Set) for sets that maintain their elements in sorted order. Class TreeSet implements SortedSet. TreeSet method headset gets a subset of the TreeSet in which every element is less than the specified value. TreeSet method tailset gets a subset in which each element is greater than or equal to the specified value. SortedSet methods first and last get the smallest and largest elements of the set, respectively. 35

36 The Set interface Hierarchy 36

37 Basic Methods Of Set interface add( ) -Adds an object to the collection. clear( ) - Removes all objects from the collection. contains( ) - Returns true if a specified object is an element within the collection. isempty( ) - Returns true if the collection has no elements iterator( ) -Returns an Iterator object for the collection, which may be used to retrieve an object. remove( ) - Removes a specified object from the collection. size( ) - Returns the number of elements in the collection. 37

38 SortedSet Implementation The collections framework also includes the SortedSet interface (which extends Set) for sets that maintain their elements in sorted order. Class TreeSet implements SortedSet. TreeSet method headset gets a subset of the TreeSet in which every element is less than the specified value. TreeSet method tailset gets a subset in which each element is greater than or equal to the specified value. SortedSet methods first and last get the smallest and largest elements of the set, respectively. 38

39 Tips On Programming With Set (1) Creating a Set Always use generics to declare a Set of specific type, e.g. a Set of integer numbers: Set<String> names = new LinkedHashSet<>(); Adding elements to a set: The add()method returns true if the set does not contain the specified element, and returns false if the set already contains the specified element: Set<String> names = new HashSet<>(); names.add("tom"); names.add("mary"); if (names.add("peter")) { System.out.printf("Peter is added to the set\n"); } if (!names.add("tom")) { System.out.printf("Tom is already added to the set\n"); } This code produces: Peter is added to the set Tom is already added to the set 39

40 Tips On Programming With Set (2) Removing elements from a Set The remove() method removes the specified element from the set if it is present and the method returns true, or false otherwise: if (names.remove("mary")) { System.out.printf("Mary is removed\n"); } Creating a union of two sets s1.addall(s2) transforms s1 into the union of s1 and s2 with no duplicate elements Set<Integer> s1 = new HashSet<>(Arrays.asList(1, 3, 5, 7, 9)); Set<Integer> s2 = new HashSet<>(Arrays.asList(2, 4, 6, 8)); System.out.printf("s1 before union: %s\n, s1) s1.addall(s2); System.out.printf("s1 after union: %s\n, s1); This code produces: s1 before union: [1, 3, 5, 7, 9] s1 after union: [1, 2, 3, 4, 5, 6, 7, 8, 9] 40

41 Tips On Programming With Set (3) Creating an intersection of two sets s1.retainall(s2) transforms s1 into the intersection of s1 and s2. Set<Integer> s1 = new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 7, 9)); Set<Integer> s2 = new HashSet<>(Arrays.asList(2, 4, 6, 8)); System.out.printf("s1 before intersection: %s\n, s1); s1.retainall(s2); System.out.printf("s1 after intersection: %s\n, s1);this code produces: s1 before intersection: [1, 2, 3, 4, 5, 7, 9] s1 after intersection: [2, 4] 41

42 42

43 What is a Map interface A Map Is A part of the Java Collection Framework, but is not derived from the Collection interface A Map object implements the map interface that maps keys to values. A Map cannot contain duplicate keys: Each key can map to at most one value - It models the mathematical function abstraction. The Map interface includes methods for basic operations (such as put, get, remove, containskey, containsvalue, size, and empty), bulk operations (such as putall and clear), and collection views (such as keyset, entryset, and values). The Java platform contains three general-purpose Map implementations: HashMap, TreeMap, and LinkedHashMap. Their behavior and performance are precisely analogous to HashSet, TreeSet, and LinkedHashSet, as described in The Set Interface section. Interface SortedMap extends Map and maintains its keys in sorted order either the elements natural order or an order specified by a Comparator. 43

44 Map Interfaces Are A Part Of the Java Collection Framework 44

45 Maps and Keys Maps associate keys to values. The keys in a Map must be unique, but the associated values need not be. If a Map contains both unique keys and unique values, it is said to implement a one-to-one mapping. If only the keys are unique, the Map is said to implement a many-to-one mapping many keys can map to one value. See TreeMapExample.java 45

46 Properties Class Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String. The Properties class is used by many other Java classes. For example, it is the type of object returned by System.getProperties( ) when obtaining environmental values. 46

47 Properties Class Methods String getproperty(string key)- Returns the value associated with the key. A null object is returned if the key is neither in the list nor in the default property list. String getproperty(string key, String defaultproperty) -Returns the value associated with the key; defaultproperty is returned if the key is neither in the list nor in the default property list. void list(printstream streamout) -Sends the property list to the output stream linked to streamout void list(printwriter streamout) -Sends the property list to the output stream linked to streamout. void load(inputstream streamin) throws IOException -Inputs a property list from the input stream linked to stream Enumeration propertynames( ) - Returns an enumeration of the keys. This includes those keys found in the default property list, too. Object setproperty(string key, String value) - Associates value with the key. Returns the previous value associated with the key, or returns null if no such association exist void store(outputstream streamout, String description) - After writing the string specified by description, the property list is written to the output stream linked to streamout. See PropertiesDemo.java 47

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Up to here Not included in program Java collections framework prebuilt data structures interfaces and methods for manipulating

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

The ArrayList class CSC 123 Fall 2018 Howard Rosenthal

The ArrayList class CSC 123 Fall 2018 Howard Rosenthal The ArrayList class CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Describe the ArrayList class Discuss important methods of this class Describe how it can be used in modeling Much of the information

More information

Introduction To Software Development CSC Spring 2019 Howard Rosenthal

Introduction To Software Development CSC Spring 2019 Howard Rosenthal Introduction To Software Development CSC 295-01 Spring 2019 Howard Rosenthal Course References Materials for this course have utilized materials in the following documents. Additional materials taken from

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

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

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

Java Collections Framework. 24 April 2013 OSU CSE 1

Java Collections Framework. 24 April 2013 OSU CSE 1 Java Collections Framework 24 April 2013 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly

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

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

Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING)

Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING) Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING) What is a Data Structure? Introduction A data structure is a particular way of organizing data using one or

More information

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other? CSM B Hashing & Heaps Spring 0 Week 0: March 0, 0 Motivation. (a) In the worst case, how long does it take to index into a linked list? Θ(N) (b) In the worst case, how long does it take to index into an

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

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

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

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

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

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

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

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

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

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

Software 1 with Java. Recitation No. 6 (Collections)

Software 1 with Java. Recitation No. 6 (Collections) Software 1 with Java Recitation No. 6 (Collections) Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2

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

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

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

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

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

Software 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface

Software 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface Java Collections Framework Collection: a group of elements Based Design: Software 1 with Java Java Collections Framework s s Algorithms Recitation No. 6 (Collections) 2 Collection s Online Resources Collection

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

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

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

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

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

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

Collection Framework Collection, Set, Queue, List, Map 3

Collection Framework Collection, Set, Queue, List, Map 3 Collection Framework Collection, Set, Queue, List, Map 3 1 1. Beginner - What is Collection? What is a Collections Framework? What are the benefits of Java Collections Framework? 3 2. Beginner - What is

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

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

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

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

[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

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 4: Generic Type and Collections Stéphane Airiau Université Paris-Dauphine Lesson 4: Generic Type and Collections (Stéphane Airiau) Java 1 Linked List 1 public class Node

More information

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6 Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself

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

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

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

Generics. IRS W-9 Form

Generics. IRS W-9 Form Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]

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 (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

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

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Lists and Iterators CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Announcements Should be making progress on VectorGraphics. Should have turned in CRC cards,

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

Core Java Contents. Duration: 25 Hours (1 Month)

Core Java Contents. Duration: 25 Hours (1 Month) Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps Lecture 12 1 Review: Data Structure A data structure is a collection of data organized in some fashion The structure not only stores data but also supports operations for accessing/manipulating the data

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

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

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures Announcements A due TOMORROW. Late deadline is Sunday. A5 released. Due next Thursday. Deadline for Prelim 1 regrade requests is tomorrow. Remember to complete your TA evaluations by tonight. HEAPS & PRIORITY

More information

www.thestudycampus.com Generic Collections 16.1 Introduction 16.2 Collections Overview 16.3 Type-Wrapper Classes 16.4 Autoboxing and Auto-Unboxing 16.5 Interface Collection and Class Collections 16.6 Lists

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources

More information

CS2113 Lab: Collections 10/29/2018

CS2113 Lab: Collections 10/29/2018 CS2113 Lab: Collections Yawei Wang 10/29/2018 Install and Use IntelliJ on Mac or Window If you haven t installed JDK before, go to https://www.oracle.com/technetwork/java/javaseproducts/downloads/in dex.html

More information

CS11 Java. Winter Lecture 8

CS11 Java. Winter Lecture 8 CS11 Java Winter 2010-2011 Lecture 8 Java Collections Very powerful set of classes for managing collections of objects Introduced in Java 1.2 Provides: Interfaces specifying different kinds of collections

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

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

Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being-

Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being- Laboratory 2 Data Structures-II Implementation of Daa structures using Collection frame work Obecjective Data Structures. A data structure is a particular way of storing and organizing data in a computer

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

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Copyright 2012, Oracle and/or its affiliates. All rights reserved. 1 Field guide to Java collections Mike Duigou (@mjduigou) Java Core Libraries 2 Required Reading Should have used most at some point List, Vector, ArrayList, LinkedList, Arrays.asList Set, HashSet, TreeSet

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Collections Framework Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi 1 Today The java.util.arrays class Java Collection Framework java.util.collection

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Collections Framework Today The java.util.arrays class Java Collection Framework java.util.collection interface java.util.list interface java.util.arraylist

More information

Tables and Priority Queues

Tables and Priority Queues Chapter 12 Tables and Priority Queues 2011 Pearson Addison-Wesley. All rights reserved 12 A-1 The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that

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

HEAPS & PRIORITY QUEUES

HEAPS & PRIORITY QUEUES HEAPS & PRIORITY QUEUES Lecture 13 CS2110 Spring 2018 Announcements 2 A4 goes out today! Prelim 1: regrades are open a few rubrics have changed No Recitations next week (Fall Break Mon & Tue) We ll spend

More information

CS2110: Software Development Methods. Maps and Sets in Java

CS2110: Software Development Methods. Maps and Sets in Java CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps This lab uses Maps, and Sets too (but just a little). Readings from textbook:

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Tables and Priority Queues!

Tables and Priority Queues! Chapter 12! Tables and Priority Queues! 2011 Pearson Addison-Wesley. All rights reserved 12 A-1 2015-11-30 21:52:31 1/49 Chapter-12.pdf (#14) The ADT Table The ADT table, or dictionary! Uses a search key

More information

CS61B Lecture #17. Last modified: Mon Oct 1 13:40: CS61B: Lecture #17 1

CS61B Lecture #17. Last modified: Mon Oct 1 13:40: CS61B: Lecture #17 1 CS61B Lecture #17 Last modified: Mon Oct 1 13:40:29 2018 CS61B: Lecture #17 1 Topics Overview of standard Java Collections classes Iterators, ListIterators Containers and maps in the abstract Amortized

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

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

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp CSE 373 Java Collection Framework reading: Weiss Ch. 3, 4.8 slides created by Marty Stepp http://www.cs.washington.edu/373/ 1 Arrays array: An object that stores many values of the same type. element:

More information

CS Programming Language Java. Fall 2004 Sept. 29

CS Programming Language Java. Fall 2004 Sept. 29 CS3101-3 Programming Language Java Fall 2004 Sept. 29 Road Map today Java review Homework review Exception revisited Containers I/O What is Java A programming language A virtual machine JVM A runtime environment

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

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

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

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

Interfaces CSC 123 Fall 2018 Howard Rosenthal

Interfaces CSC 123 Fall 2018 Howard Rosenthal Interfaces CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Defining an Interface How a class implements an interface Using an interface as a data type Default interfaces Implementing multiple interfaces

More information

Frameworks. CS151 Chris Pollett Oct. 26, 2005.

Frameworks. CS151 Chris Pollett Oct. 26, 2005. Frameworks CS151 Chris Pollett Oct. 26, 2005. Outline Collections Framework GUI Frameworks - AWT and Swing The Java Collection Framework Last day, we began discussing the Java collection Framework. We

More information

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 103: Test

More information

Lecture 16: Case Study: The Java Collections API

Lecture 16: Case Study: The Java Collections API Lecture 16: Case Study: The Java Collections API You can t be a competent Java programmer without understanding the crucial parts of the Java library. The basic types are all in java.lang, and are part

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

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

Announcements/Follow-ups

Announcements/Follow-ups Announcements/Follow-ups Midterm 2 graded Average was 52/80 (63%), Std. Dev. was 12 P5 and Lab8 P5 due tomorrow Very light Lab8 Practice with collections Due at end of lab period P6 posted tomorrow Due

More information

Data Structures and Abstractions with Java

Data Structures and Abstractions with Java Global edition Data Structures and Abstractions with Java Fourth edition Frank M. Carrano Timothy M. Henry Data Structures and Abstractions with Java TM Fourth Edition Global Edition Frank M. Carrano University

More information

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries 1 CONTENTS 1. Introduction to Java 2. Holding Data 3. Controllin g the f l o w 4. Object Oriented Programming Concepts 5. Inheritance & Packaging 6. Handling Error/Exceptions 7. Handling Strings 8. Threads

More information

COMP 250. Lecture 32. interfaces. (Comparable, Iterable & Iterator) Nov. 22/23, 2017

COMP 250. Lecture 32. interfaces. (Comparable, Iterable & Iterator) Nov. 22/23, 2017 COMP 250 Lecture 32 interfaces (Comparable, Iterable & Iterator) Nov. 22/23, 2017 1 Java Comparable interface Suppose you want to define an ordering on objects of some class. Sorted lists, binary search

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

Collections, Maps and Generics

Collections, Maps and Generics Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.

More information

Collections and Iterators. Collections

Collections and Iterators. Collections Collections and Iterators Based on the notes from David Fernandez-Baca and Steve Kautz Based on The Java Tutorial (http://docs.oracle.com/javase/tutorial/java/) Bryn Mawr College CS206 Intro to Data Structures

More information

5/23/2015. Core Java Syllabus. VikRam ShaRma

5/23/2015. Core Java Syllabus. VikRam ShaRma 5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5

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