SlideShare a Scribd company logo
1 of 12
1. what all collection you used in your project ?
Interview Q&A
CopyOnWriteArrayList CopyOnWriteArraySet ConcurrentHashMap
java.util.concurrent.*
2. What is the difference between list and set ?
3. What is the Difference between ArrayList and LinkedList ?
Interview Q&A
CopyOnWriteArrayList CopyOnWriteArraySet ConcurrentHashMap
ArrayList LinkedList
ArrayList internally uses a dynamic array
to store the elements
LinkedList internally uses a doubly
linked list to store the elements.
Manipulation with ArrayList is slow
because it internally uses an array. If
any element is removed from the array,
all the bits are shifted in memory
Manipulation with LinkedList is faster
than ArrayList because it uses a doubly
linked list, so no bit shifting is required
in memory.
ArrayList is better for storing and
accessing data
LinkedList is better for manipulating
data.
4. List object creation scenario
ArrayList arrayList=new ArrayList<String>();
List<String> list=new ArrayList<>();
5. Declaring a List field with the final keyword ?
6. How Can I write Custom ArrayList where I don’t want to allow duplicate ?
7. Why Set doesn’t allow duplicate Element ?
8. What is the difference between Comparable and Comparator ?
Interview Q&A
Interview Q&A
CopyOnWriteArrayList CopyOnWriteArraySet ConcurrentHashMap
9. Multi Comparing using Comparator Scenario
10. What is the difference between fail fast and fail safe iterator
• A iterator which will fail fast when we do any modification while iterating a collection is
called fail fast iterator Ex : (ArrayList ,HashMap and Vector)
• Iterator who allow us to modify in middle while iterating a collection is called Non-Fail
Fast Iterator Ex: (CopyOnWriteArrayList , CopyOnWriteArraySet, ConcurrentHashMap)
• Example
• Internal Flow
Interview Q&A
11. What is the need of ConcurrentHashMap and How it is different
from HashMap ?
Interview Q&A
12. If we have Hashtable which is already synchronized then why we need
ConcurrentHashMap ?
Ans : Locking Mechanism still same as per HashMap (lock whole underlaying DS)
Interview Q&A
13. We Can Synchronize a HashMap using Collections then why can’t we use
that instead using ConcurrentHashMap ?
Ans : if we used Collections.synchronizedMap(map) it will act as a
synchronized Hashtable only where again locking mechanism is different
14. How HashMap Internally Works
Interview Q&A
Interview Q&A
Map<Employee, String> map=new HashMap<>();
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
LinkedList
Node
key value hash next
Employee e1=new Employee(101,”Basant”)
Employee e2=new Employee(102,”peter”)
Employee e3=new Employee(103,”John”)
Employee e4=new Employee(104,”Sham”)
map.put(e1,”Dev”)
6
e1 Dev 1011 null
map.put(e2,”QA”)
9
e2 QA 2345 null
map.put(e3,”UI”)
6
e3 UI 7976 null
e2.equals(e3)
map.put(e4,”UI”)
7
e4 UI 6789 null
map.put(null,”UI”)
null UI 6789 null
Interview Q&A
15. If key is null in HashMap then where that entry will store in map ?
16. Map enhancement in java 8
17. How TreeMap internally works
Interview Q&A

More Related Content

Similar to Collection-Q&A.pptx

Similar to Collection-Q&A.pptx (20)

Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Java mcq
Java mcqJava mcq
Java mcq
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Java Collections.pptx
Java Collections.pptxJava Collections.pptx
Java Collections.pptx
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
 
Any Which Array But Loose
Any Which Array But LooseAny Which Array But Loose
Any Which Array But Loose
 
‘go-to’ general-purpose sequential collections - from Java To Scala
‘go-to’ general-purpose sequential collections -from Java To Scala‘go-to’ general-purpose sequential collections -from Java To Scala
‘go-to’ general-purpose sequential collections - from Java To Scala
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
Perl and Elasticsearch
Perl and ElasticsearchPerl and Elasticsearch
Perl and Elasticsearch
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Javasession7
Javasession7Javasession7
Javasession7
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Collection-Q&A.pptx

  • 1.
  • 2. 1. what all collection you used in your project ? Interview Q&A CopyOnWriteArrayList CopyOnWriteArraySet ConcurrentHashMap java.util.concurrent.*
  • 3. 2. What is the difference between list and set ? 3. What is the Difference between ArrayList and LinkedList ? Interview Q&A CopyOnWriteArrayList CopyOnWriteArraySet ConcurrentHashMap ArrayList LinkedList ArrayList internally uses a dynamic array to store the elements LinkedList internally uses a doubly linked list to store the elements. Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory. ArrayList is better for storing and accessing data LinkedList is better for manipulating data.
  • 4. 4. List object creation scenario ArrayList arrayList=new ArrayList<String>(); List<String> list=new ArrayList<>(); 5. Declaring a List field with the final keyword ? 6. How Can I write Custom ArrayList where I don’t want to allow duplicate ? 7. Why Set doesn’t allow duplicate Element ? 8. What is the difference between Comparable and Comparator ? Interview Q&A
  • 6. 9. Multi Comparing using Comparator Scenario 10. What is the difference between fail fast and fail safe iterator • A iterator which will fail fast when we do any modification while iterating a collection is called fail fast iterator Ex : (ArrayList ,HashMap and Vector) • Iterator who allow us to modify in middle while iterating a collection is called Non-Fail Fast Iterator Ex: (CopyOnWriteArrayList , CopyOnWriteArraySet, ConcurrentHashMap) • Example • Internal Flow Interview Q&A
  • 7. 11. What is the need of ConcurrentHashMap and How it is different from HashMap ? Interview Q&A
  • 8. 12. If we have Hashtable which is already synchronized then why we need ConcurrentHashMap ? Ans : Locking Mechanism still same as per HashMap (lock whole underlaying DS) Interview Q&A
  • 9. 13. We Can Synchronize a HashMap using Collections then why can’t we use that instead using ConcurrentHashMap ? Ans : if we used Collections.synchronizedMap(map) it will act as a synchronized Hashtable only where again locking mechanism is different 14. How HashMap Internally Works Interview Q&A
  • 10. Interview Q&A Map<Employee, String> map=new HashMap<>(); 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 LinkedList Node key value hash next Employee e1=new Employee(101,”Basant”) Employee e2=new Employee(102,”peter”) Employee e3=new Employee(103,”John”) Employee e4=new Employee(104,”Sham”) map.put(e1,”Dev”) 6 e1 Dev 1011 null map.put(e2,”QA”) 9 e2 QA 2345 null map.put(e3,”UI”) 6 e3 UI 7976 null e2.equals(e3) map.put(e4,”UI”) 7 e4 UI 6789 null map.put(null,”UI”) null UI 6789 null
  • 12. 15. If key is null in HashMap then where that entry will store in map ? 16. Map enhancement in java 8 17. How TreeMap internally works Interview Q&A