SlideShare a Scribd company logo
Java collections framework
Commonly reusable collection data structures
Java Collections Framework (JCF)
A.A. 2012/2013Tecniche di programmazione2
Collection
an object that represents a group of objects
Collection Framework
A unified architecture for representing and manipulating
collections
Such collections are manipulated independent of the details of
their representation
“JCF” vs.“ADT”
A little bit of history…
A.A. 2012/2013Tecniche di programmazione3
JDK < 1.2
Standard practice: Vector and Hashtable
Compatibility with C++ StandardTemplate Library (STL)
Doug Lea’s Collections package
ObjectSpace Generic Collection Library (JGL)
JDK ≥1.2
Sun drops compatibility with C++ STL
Joshua Bloch’s JCF
(now Chief Java Architect @ Google)
A little bit of history…
A.A. 2012/2013Tecniche di programmazione4
Java 5
Introduction of <generics>
Clean, safe definition of the Collection Interface
Trees, linked lists, stacks, hash tables, and other classes are
implementations of Collection
Arrays do not implement the Collection interface
Vector redefined to implement Collection
A little bit of history…
A.A. 2012/2013Tecniche di programmazione5
Doug Lea later developed a concurrency package
JCF’s Main Elements
A.A. 2012/2013Tecniche di programmazione6
Infrastructure
Interfaces that provide essential support for the collection
interfaces
General-purpose Implementations
Primary implementations (basic and bulk) of the collection
interfaces
Algorithms
A.A. 2012/2013Tecniche di programmazione7
Algorithms
Static methods that perform useful functions on collections,
such as sorting a list
ICF’s Utility Implementations
A.A. 2012/2013Tecniche di programmazione8
Legacy Implementations
The collection classes from earlier releases,Vector and
Hashtable, have been retrofitted to implement the collection
interfaces
Convenience Implementations
High-performance "mini-implementations" of the collection
interfaces
Wrapper Implementations
Add functionality, such as synchronization, to other
implementations
Abstract Implementations
A.A. 2012/2013Tecniche di programmazione9
Partial implementations (skeletons) of the collection
interfaces to facilitate custom implementations
Infrastructure
A.A. 2012/2013Tecniche di programmazione10
These interfaces form the basis of the framework
Some types of collections allow duplicate elements, others do not
Some types of collections are ordered, others are unordered
The Java platform doesn’t provide any direct implementations
of the Collection interface, but provides implementations of
more specific sub-interfaces, such as Set and List and Maps
Collection interface
A.A. 2012/2013Tecniche di programmazione11
A Collection represents a group of objects known
as its elements
The Collection interface is the least common
denominator that all collections implement.
It is Used
to pass collections around
to manipulate them when maximum generality is desire
Collection extends Iterable
A note on iterators
A.A. 2012/2013Tecniche di programmazione12
An Iterator is an object that enables you to traverse
through a collection (and to remove elements from the
collection selectively)
You get an Iterator for a collection by calling its iterator()
method.
Several languages supports “iterators”. E.g., C++, PHP,
Python, Ruby, Go…
public interface Iterator<E> {
boolean hasNext();
E next();
void remove(); //optional
}
Main Interfaces
A.A. 2012/2013Tecniche di programmazione13
List
A more flexible version of an array
Queue & Priority Queue
The order of arrival does matter, or the urgency
Set
No order, no duplicate elements
Map interface
A.A. 2012/2013Tecniche di programmazione14
A Map is an object that maps keys to values
A map cannot contain duplicate keys: each key can map
to at most one value
Map does not extend Iterable, but it is possible to
get an iterator through entrySet()
Notez bien: Maps do not extend from
java.util.Collection, but they’re still considered to
be part of the “collections framework”
Collection Family Tree
A.A. 2012/2013Tecniche di programmazione15
Collection interface
A.A. 2012/2013Tecniche di programmazione16
public interface Collection<E> extends Iterable<E> {
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
Object[] toArray();
<T>T[] toArray(T[] a);
}
Collection interface
A.A. 2012/2013Tecniche di programmazione17
public interface Collection<E> extends Iterable<E> {
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
Object[] toArray();
<T>T[] toArray(T[] a);
}
Basic Operations
generics
Collection interface
A.A. 2012/2013Tecniche di programmazione18
public interface Collection<E> extends Iterable<E> {
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
Object[] toArray();
<T>T[] toArray(T[] a);
}
Bulk Operations
wildcard
either extends
or implements
Collection interface
A.A. 2012/2013Tecniche di programmazione19
public interface Collection<E> extends Iterable<E> {
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
Object[] toArray();
<T>T[] toArray(T[] a);
}
Array Operations
Licenza d’uso
A.A. 2012/2013Tecniche di programmazione21
Queste diapositive sono distribuite con licenza Creative Commons
“Attribuzione - Non commerciale - Condividi allo stesso modo (CC
BY-NC-SA)”
Sei libero:
di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,
rappresentare, eseguire e recitare quest'opera
di modificare quest'opera
Alle seguenti condizioni:
Attribuzione — Devi attribuire la paternità dell'opera agli autori
originali e in modo tale da non suggerire che essi avallino te o il modo in
cui tu usi l'opera.
Non commerciale — Non puoi usare quest'opera per fini
commerciali.
Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se
la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una
licenza identica o equivalente a questa.
http://creativecommons.org/licenses/by-nc-sa/3.0/

More Related Content

What's hot

Java Collections
Java  Collections Java  Collections
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
Rahman USTA
 
What's new in Scala 2.13?
What's new in Scala 2.13?What's new in Scala 2.13?
What's new in Scala 2.13?
Hermann Hueck
 
Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8
RichardWarburton
 
03. oop concepts
03. oop concepts03. oop concepts
03. oop concepts
Haresh Jaiswal
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
Andrzej Grzesik
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java
 
A Taste of Dotty
A Taste of DottyA Taste of Dotty
A Taste of Dotty
Hermann Hueck
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
mentorrbuddy
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
Rakesh Waghela
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
Manvendra Singh
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
phanleson
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
Nico Ludwig
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
Jim Bethancourt
 
Generics
GenericsGenerics
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
Shalabh Chaudhary
 

What's hot (20)

Java Collections
Java  Collections Java  Collections
Java Collections
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
What's new in Scala 2.13?
What's new in Scala 2.13?What's new in Scala 2.13?
What's new in Scala 2.13?
 
Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)
 
Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8
 
03. oop concepts
03. oop concepts03. oop concepts
03. oop concepts
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
A Taste of Dotty
A Taste of DottyA Taste of Dotty
A Taste of Dotty
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
 
07 java collection
07 java collection07 java collection
07 java collection
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Generics
GenericsGenerics
Generics
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 

Similar to Java collections framework

JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
boopathirajaraja1
 
JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
Irfanhabeeb18
 
Collections
CollectionsCollections
Lecture 24
Lecture 24Lecture 24
Lecture 24
Debasish Pratihari
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Carl Brown
 
Java 8
Java 8Java 8
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
Simon Ritter
 
SCALA - Functional domain
SCALA -  Functional domainSCALA -  Functional domain
SCALA - Functional domain
Bartosz Kosarzycki
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
Dinesh Pathak
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
RichardWarburton
 
Topic-G-JavaCollections Framework.ppt
Topic-G-JavaCollections    Framework.pptTopic-G-JavaCollections    Framework.ppt
Topic-G-JavaCollections Framework.ppt
swapnilslide2019
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
Robert Bachmann
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
C4Media
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
 
collections
collectionscollections
collections
javeed_mhd
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
Jörn Guy Süß JGS
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
YoungSu Son
 
Java Collections
Java CollectionsJava Collections
Java Collections
rithustutorials
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
jaxLondonConference
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
RichardWarburton
 

Similar to Java collections framework (20)

JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
 
JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
 
Collections
CollectionsCollections
Collections
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
 
Java 8
Java 8Java 8
Java 8
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
 
SCALA - Functional domain
SCALA -  Functional domainSCALA -  Functional domain
SCALA - Functional domain
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
 
Topic-G-JavaCollections Framework.ppt
Topic-G-JavaCollections    Framework.pptTopic-G-JavaCollections    Framework.ppt
Topic-G-JavaCollections Framework.ppt
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
collections
collectionscollections
collections
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 

Recently uploaded

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 

Recently uploaded (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 

Java collections framework

  • 1. Java collections framework Commonly reusable collection data structures
  • 2. Java Collections Framework (JCF) A.A. 2012/2013Tecniche di programmazione2 Collection an object that represents a group of objects Collection Framework A unified architecture for representing and manipulating collections Such collections are manipulated independent of the details of their representation “JCF” vs.“ADT”
  • 3. A little bit of history… A.A. 2012/2013Tecniche di programmazione3 JDK < 1.2 Standard practice: Vector and Hashtable Compatibility with C++ StandardTemplate Library (STL) Doug Lea’s Collections package ObjectSpace Generic Collection Library (JGL) JDK ≥1.2 Sun drops compatibility with C++ STL Joshua Bloch’s JCF (now Chief Java Architect @ Google)
  • 4. A little bit of history… A.A. 2012/2013Tecniche di programmazione4 Java 5 Introduction of <generics> Clean, safe definition of the Collection Interface Trees, linked lists, stacks, hash tables, and other classes are implementations of Collection Arrays do not implement the Collection interface Vector redefined to implement Collection
  • 5. A little bit of history… A.A. 2012/2013Tecniche di programmazione5 Doug Lea later developed a concurrency package
  • 6. JCF’s Main Elements A.A. 2012/2013Tecniche di programmazione6 Infrastructure Interfaces that provide essential support for the collection interfaces General-purpose Implementations Primary implementations (basic and bulk) of the collection interfaces
  • 7. Algorithms A.A. 2012/2013Tecniche di programmazione7 Algorithms Static methods that perform useful functions on collections, such as sorting a list
  • 8. ICF’s Utility Implementations A.A. 2012/2013Tecniche di programmazione8 Legacy Implementations The collection classes from earlier releases,Vector and Hashtable, have been retrofitted to implement the collection interfaces Convenience Implementations High-performance "mini-implementations" of the collection interfaces Wrapper Implementations Add functionality, such as synchronization, to other implementations
  • 9. Abstract Implementations A.A. 2012/2013Tecniche di programmazione9 Partial implementations (skeletons) of the collection interfaces to facilitate custom implementations
  • 10. Infrastructure A.A. 2012/2013Tecniche di programmazione10 These interfaces form the basis of the framework Some types of collections allow duplicate elements, others do not Some types of collections are ordered, others are unordered The Java platform doesn’t provide any direct implementations of the Collection interface, but provides implementations of more specific sub-interfaces, such as Set and List and Maps
  • 11. Collection interface A.A. 2012/2013Tecniche di programmazione11 A Collection represents a group of objects known as its elements The Collection interface is the least common denominator that all collections implement. It is Used to pass collections around to manipulate them when maximum generality is desire Collection extends Iterable
  • 12. A note on iterators A.A. 2012/2013Tecniche di programmazione12 An Iterator is an object that enables you to traverse through a collection (and to remove elements from the collection selectively) You get an Iterator for a collection by calling its iterator() method. Several languages supports “iterators”. E.g., C++, PHP, Python, Ruby, Go… public interface Iterator<E> { boolean hasNext(); E next(); void remove(); //optional }
  • 13. Main Interfaces A.A. 2012/2013Tecniche di programmazione13 List A more flexible version of an array Queue & Priority Queue The order of arrival does matter, or the urgency Set No order, no duplicate elements
  • 14. Map interface A.A. 2012/2013Tecniche di programmazione14 A Map is an object that maps keys to values A map cannot contain duplicate keys: each key can map to at most one value Map does not extend Iterable, but it is possible to get an iterator through entrySet() Notez bien: Maps do not extend from java.util.Collection, but they’re still considered to be part of the “collections framework”
  • 15. Collection Family Tree A.A. 2012/2013Tecniche di programmazione15
  • 16. Collection interface A.A. 2012/2013Tecniche di programmazione16 public interface Collection<E> extends Iterable<E> { int size(); boolean isEmpty(); boolean contains(Object element); boolean add(E element); //optional boolean remove(Object element); //optional Iterator<E> iterator(); boolean containsAll(Collection<?> c); boolean addAll(Collection<? extends E> c); //optional boolean removeAll(Collection<?> c); //optional boolean retainAll(Collection<?> c); //optional void clear(); //optional Object[] toArray(); <T>T[] toArray(T[] a); }
  • 17. Collection interface A.A. 2012/2013Tecniche di programmazione17 public interface Collection<E> extends Iterable<E> { int size(); boolean isEmpty(); boolean contains(Object element); boolean add(E element); //optional boolean remove(Object element); //optional Iterator<E> iterator(); boolean containsAll(Collection<?> c); boolean addAll(Collection<? extends E> c); //optional boolean removeAll(Collection<?> c); //optional boolean retainAll(Collection<?> c); //optional void clear(); //optional Object[] toArray(); <T>T[] toArray(T[] a); } Basic Operations generics
  • 18. Collection interface A.A. 2012/2013Tecniche di programmazione18 public interface Collection<E> extends Iterable<E> { int size(); boolean isEmpty(); boolean contains(Object element); boolean add(E element); //optional boolean remove(Object element); //optional Iterator<E> iterator(); boolean containsAll(Collection<?> c); boolean addAll(Collection<? extends E> c); //optional boolean removeAll(Collection<?> c); //optional boolean retainAll(Collection<?> c); //optional void clear(); //optional Object[] toArray(); <T>T[] toArray(T[] a); } Bulk Operations wildcard either extends or implements
  • 19. Collection interface A.A. 2012/2013Tecniche di programmazione19 public interface Collection<E> extends Iterable<E> { int size(); boolean isEmpty(); boolean contains(Object element); boolean add(E element); //optional boolean remove(Object element); //optional Iterator<E> iterator(); boolean containsAll(Collection<?> c); boolean addAll(Collection<? extends E> c); //optional boolean removeAll(Collection<?> c); //optional boolean retainAll(Collection<?> c); //optional void clear(); //optional Object[] toArray(); <T>T[] toArray(T[] a); } Array Operations
  • 20.
  • 21. Licenza d’uso A.A. 2012/2013Tecniche di programmazione21 Queste diapositive sono distribuite con licenza Creative Commons “Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA)” Sei libero: di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico, rappresentare, eseguire e recitare quest'opera di modificare quest'opera Alle seguenti condizioni: Attribuzione — Devi attribuire la paternità dell'opera agli autori originali e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera. Non commerciale — Non puoi usare quest'opera per fini commerciali. Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa. http://creativecommons.org/licenses/by-nc-sa/3.0/