Module 9 Collections
Module 9 Collections
(Java)
Module 9
Collections
Learn how to manipulate and manage data
Understand when and where to use different collection
types
Understand and define the advantage of Generic
Collection
9.1
Collections
Collection
ØThe Collection in Java is a framework that provides an architecture to store and manipulate the
group of objects.
Ø Java Collections can achieve all the operations that you perform on a data such as searching,
sorting, insertion, manipulation, and deletion.
Ø Java Collection means a single unit of objects. Java Collection framework provides many
interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue,
HashSet, LinkedHashSet, TreeSet).
Collections
Collection
Collections
Hierarchy of Collection Framework
ØThe java.util package contains all the classes and interfaces for the Collection framework.
Collections
Methods of Collection interface
• Collection 8
Methods of Collection interface
Collections
Iterable Interface
Ø The Iterable interface is the root interface for all the collection classes. The Collection interface
extends the Iterable interface and therefore all the subclasses of Collection interface also implement
the Iterable interface.
Collections
Collection Interface
Ø The Collection interface is the interface which is implemented by all the classes in the collection
framework. It declares the methods that every collection will have. In other words, we can say that
the Collection interface builds the foundation on which the collection framework depends.
Ø Some of the methods of Collection interface are Boolean add ( Object obj), Boolean addAll (
Collection c), void clear(), etc. which are implemented by all the subclasses of Collection interface.
Collections
List Interface
Ø List interface is the child interface of Collection interface. It inhibits a list type data structure in
which we can store the ordered collection of objects. It can have duplicate values.
Ø List interface is implemented by the classes ArrayList, LinkedList, Vector, and Stack.
Ø To instantiate the List interface, we must use :
Ø There are various methods in List interface that can be used to insert, delete, and access the
elements from the list.
Collections
ArrayList
Collections
LinkedList
Collections
Vector
Collections
Stack
Collections
Collections Part 2
9.1
Collections
Queue Interface
Ø Queue interface maintains the first-in-first-out order. It can be defined as an ordered list that is
used to hold the elements which are about to be processed. There are various classes like
PriorityQueue, Deque, and ArrayDeque which implements the Queue interface.
Collections
PriorityQueue
Collections 19
Deque Interface
Ø Deque interface extends the Queue interface. In Deque, we can remove and add the
elements from both the side. Deque stands for a double-ended queue which enables us to
perform the operations at both the ends.
Ø Deque can be instantiated as:
Collections
ArrayDeque
Collections
Set Interface
Ø Set Interface in Java is present in java.util package. It extends the Collection interface. It
represents the unordered set of elements which doesn't allow us to store the duplicate items. We
can store at most one null value in Set. Set is implemented by HashSet, LinkedHashSet, and
TreeSet.
Collections
Hashset
Collections
Linked Hashset
Collections
SortedSet Interface
Ø SortedSet is the alternate of Set interface that provides a total ordering on its elements. The
elements of the SortedSet are arranged in the increasing (ascending) order. The SortedSet
provides the additional methods that inhibit the natural ordering of the elements.
Collections
TreeSet
Collections
Backiel, A. (2015). Beginning Java Programming: The Object-oriented Approach. 1st Edition
Fain, Y. (2015). Java programming 24-hour trainer. John Wiley and Sons:Indianapolis, IN
Smith, J. (2015). Java programs to accompany Programming logic and design. Cengage Learning:Boston, MA
Yener, M (2015). Professional Java EE Design Patterns. John Wiley & Sons, Inc.
Gordon, S. (2017). Computer Graphics Programming in opengl with Java. Mercury Learning and Information
Butler, A (2017). Java. s.n
Lowe, D (2017). Java all-in-one for dummies. John Wiley and Sons
Saumont, P (2017). Functional Programming in Java: How Functional Techniques Improve Your Java Programs. 1st Edition
Heffelfinger, D. (2017). Java EE 8 Application Development. Packt Puublishing
Murach, J. (2017). Murach’s Java Programming. Mike Murach & Associates,Inc.
Burd, B. (2017). Beginning programming with Java for dummies. John Wiley & Sons, Inc.
Manelli, L. (2017). Developing java web application in a day. s.n.
Klausen, P. (2017). Java 5: Files and Java IO software development (e-book)
Klausen, P. (2017). Java 3 object-oriented programming software development (e-book)
Muller, M (2018). Practical JSF in Java EE 8. Apress