Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
121 views
34 Java Collections Interview Questions
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 34 Java Collections Interview Questions For Later
Download
Save
Save 34 Java Collections Interview Questions For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
121 views
34 Java Collections Interview Questions
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 34 Java Collections Interview Questions For Later
Carousel Previous
Carousel Next
Save
Save 34 Java Collections Interview Questions For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 21
Search
Fullscreen
‘2122, 1:58 PM Java Collections Interview Questions (2023) javatpoint Home Interview Questions ava sau Pythor JavaSerip Angula JaveW7 root rrr) eee ie SCROLL TO TOP Bites |nps:iiwwjavalpoin comijava-colectonsnteriew-questions at‘2122, 1:58 PM Java Collections Interview Questions (2023) javatpoint 34 Java Collections Interview Questions In Java, collection interview questions are most asked by the interviewers, Here is the list of the most asked collections interview questions with answers. 1) What is the Collection framework in Java? Collection Framework is a combination of classes and interface, which is used to store and manipulate the data in the form of objects. It provides various classes such as ArrayList, Vector, Stack, and HashSet, etc. and interfaces such as List, Queue, Set, etc. for this purpose. 2) What are the main differences between array and collection? Array and Collection are somewhat similar regarding storing the references of objects and manipulating the data, but they differ in many ways. The main differences between the array and Collection are defined below: © Arrays are always of fixed size, ie., a user can not increase or decrease the length of the array according to their requirement or at runtime, but In Collection, size can be changed dynamically as per need. © Arrays can only store homogeneous or similar type objects, but in Collection, heterogeneous objects can be stored. © Arrays cannot provide the ?ready-made? methods for user requirements as sorting, searching, etc, but Collection includes readymade methods to use. 3) Explain various interfaces used in Collection framework? Collection framework implements various interfaces, Collection interface and Map interface (ava.utilMap) are the mainly used interfaces of Java Collection Framework. List of interfaces of Collection Framework is given belo |nps:iiwwjavalpoin comijava-cotectonsnteriew-questions‘2122, 1:58 PM Java Collections Interview Questions (2023) javatpoint 1. Collection interface: Collection (java.util.Collection) is the primary interface, and every collection must implement this interface. Syntax: public interface Collection
extends Iterable Where
represents that this interface is of Generic type 2. List interface: List interface extends the Collection interface, and it is an ordered collection of objects. It contains duplicate elements. It also allows random access of elements. Syntax: | public interface List
extends Collection
3. Set interface: Set (java.util.Set) interface is a collection which cannot contain duplicate elements. It can only include inherited methods of Collection interface Syntax: interface Set
extends Collection
[= Queue interface: Queue (java.util. Queue) interface defines queue data structure, which stores the elements in the form FIFO (first in first out) -nps:ihwwjavalpoin comijava-colectonsnterview-questions a1‘2122, 1:58 PM Java Collections Interview Questions (2023) javatpoint Syntax: public interface Queue
extends Collection<€> 4, Dequeue interface: it is a double-ended-queue. It allows the insertion and removal of elements from both ends. it implants the properties of both Stack and queue so it can perform LIFO (Last in first out) stack and FIFO (first in first out) queue, operations. Syntax: public interface Dequeue
extends Queue
5. Map interface: A Map (java.util.Map) represents a key, value pair storage of elements. Map interface does not implement the Collection interface. It can only contain a unique key but can have duplicate elements, There are two interfaces which implement Map in java that are Map interface and Sorted Map. 4) What is the difference between ArrayList and Vector? No, ArrayList Vector 1) ArrayList is not synchronized. Vector is synchronized. 2) ArrayList is not a legacy class. Vector is a legacy class. 3) ArrayList increases its size by 50% of the Vector increases its size by doubling the array array size. size. 4) ArrayList is not ?thread-safe? as it is not Vector list ic ?thread-cafe? ac it?< every methad synchronized. is sync 5) What is the difference between ArrayList : No. ArrayList LinkedL. |nps:ihwwjavalpoin comijava-colectons-nterview-questions aans21raina, 11:58 PM 1) ArrayList uses a dynamic array. 2) Arraylist' is not efficient for manipulation because too much is required. 3) ArrayList is better to store and fetch data. 4) ArrayList provides random access. 5) ArrayList takes less memory overhead as it stores only object 6) What is the difference between Ite! Iterator traverses the elements in the forward elements into forward and backward direction. No. Iterator 1) The Iterator traverses the elements in the forward direction only. 2) The Iterator can be used in List, Set, and Queue, 3) The Iterator can only perform remove operation while traversing the collection |nps:iiwwjavalpoin comijava-colectonsnterview-questions Java Collections Interview Questions (2023) javatpoint LinkedList uses a doubly linked list. LinkedList is efficient for manipulation. LinkedList is better to manipulate data, LinkedList does not provide random access. LinkedList takes more memory overhead, as it stores the object as well as the address of that object rator and Listlterator? direction only whereas Listiterator traverses the Listlterator Listiterator traverses the elements in backward and forward directions both. Listiterator can be used in List only. Listlter, set? op‘2am, 154M Java Colectons Interview Questions (2023) javatpoint 7) What is the difference between Iterator and Enumeration? No. Iterator Enumeration 1) The Iterator can traverse legacy and non- Enumeration can traverse only legacy legacy elements. elements. 2) The Iterator is fail-fast. Enumeration is not fail-fast. 3) The Iterator is slower than Enumeration. Enumeration is faster than Iterator. 4) The Iterator can perform remove operation |The Enumeration can perform only traverse while traversing the collection operation on the collection. 8) What is the difference between List and Set? The List and Set both extend the collection interface. However, there are some differences between the both which are listed below. © The List can contain duplicate elements whereas Set includes unique items. © The List is an ordered collection which maintains the insertion order whereas Set is an unordered collection which does not preserve the insertion order. © The List interface contains a single legacy class which is Vector class whereas Set interface does not have any legacy class. © The List interface can allow n number of null values whereas Set interface only allows a single null value. |nps:iiwwjavalpoin comijava-cotectonsnteriew-questions 621s21ramna, 1:58 PM Java Collections Interview Questions (2023) javatpoint 9) What is the difference between HashSet and TreeSet? The HashSet and TreeSet, both classes, implement Set interface. The differences between the both are listed below. ° HashSet maintains no order whereas TreeSet maintains ascending order. ° HashSet impended by hash table whereas TreeSet implemented by a Tree structure. ° HashSet performs faster than TreeSet. ° HashSet is backed by HashMap whereas TreeSet is backed by TreeMap. 10) What is the difference between Set and Map? The differences between the Set and Map are given below. © Set contains values only whereas Map contains key and values both. © Set contains unique values whereas Map can contait © Set holds a single number of null value whereas number of null values. |nps:iiwwjavalpoin comijava-colectonsnteriew-questions mas21eare2, 1:58 PM Java Collections Interview Questions (2023) javatpoint 11) What is the difference between HashSet and HashMap? The differences between the HashSet and HashMap are listed below. HashSet contains only values whereas HashMap includes the entry (key, value). HashSet can be iterated, but HashMap needs to convert into Set to be iterated. HashSet implements Set interface whereas HashMap implements the Map interface HashSet cannot have any duplicate value whereas HashMap can contain duplicate values with unique keys. HashSet contains the only single number of null value whereas HashMap can hold a single null key with n number of null values. 12) What is the difference between HashMap and TreeMap? The differences between the HashMap and TreeMap are given below. HashMap maintains no order, but TreeMap maintains ascending order. HashMap is implemented by hash table whereas TreeMap is implemented by a Tree structure, HashMap can be sorted by Key or value whereas TreeMap can be sorted by Key. HashMap may contain a null key with multiple null values whereas TreeMap cannot hold a null key but can have multiple null values 13) What is the difference between HashMap and Hashtable? No. 1) 3) HashMap Hashtable HashMap is not synchronized. Hashtable is synchronized. HashMap can contain one null key and Hashtable cannot contain any null key or multiple null values. ne HashMap is not ?thread-safe,? so it is useful Hi for non-threaded applications. sh 4) HashMap inherits the AbstractMap class H: hitps:ww javatpoint comjava-colections-intrviow-questions a1‘2am, 154M Java Collections Itervew Questions (2023)-javatpoin 14) What is the difference between Collection and Collections? The differences between the Collection and Collections are given below. © The Collection is an interface whereas Collections is a class. © The Collection interface provides the standard functionality of data structure to List, Set, and Queue. However, Collections class is to sort and synchronize the collection elements. © The Collection interface provides the methods that can be used for data structure whereas Collections class provides the static methods which can be used for various operation on a collection. 15) What is the difference between Comparable and Comparator? No. Comparable Comparator 1) Comparable provides only one sort of sequence. The Comparator provides multiple sorts of sequences. 2) It provides one method named compareTo0. It provides one method named compare() 3) Itis found in javatang package. Itis located in java.util package 4) If we implement the Comparable interface, The The actual class is not changed actual class is modified. 16) What do you understand by BlockingQueue? BlockingQueue is an interface which extends the Queue interface. It provides concurrency in the operations like retrieval, insertion, deletion. While retrieval of any element, it waits for the queue to be non-empty. While storing the elements, it waits for the availahle cnara. RlacbinnMnane cannot contain null elements, and implementation of BlockingQui Syntax: public interface BlockingQueue
extends Queue
list=new Arraylist
(); list.add(‘ankit’); list.add(“nippun"); System.out.printin(list.size(); 28) How to convert ArrayList to Array and Array to ArrayList? We can convert an Array to ArrayList by using the asList() the static method of Arrays class and accepts the List obje Arrays.asList(item) |nps:iiwwjavalpoin comijava-colectonsnteriew-questions va‘2am, 154M Java Collections Itervew Questions (2023)-javatpoin We can convert an ArrayList to Array using toArray) method of the ArrayList class. Consider the following syntax to convert the ArrayList to the List object List_object:toArray(new String[List_objectsize(]) 29) How to make Java ArrayList Read-Only? We can obtain java ArrayList Read-only by calling the Collections.unmodifiableCollection() method When we define an ArrayList as Read-only then we cannot perform any modification in the collection through add(), remove() or set() method. 30) How to remove duplicates from ArrayList? There are two ways to remove duplicates from the ArrayList. © Using HashSet: By using HashSet we can remove the duplicate element from the ArrayList, but it will not then preserve the insertion order. © Using LinkedHashSet: We can also maintain the insertion order by using LinkedHashSet instead of HashSet. The Process to remove duplicate elements from ArrayList using the LinkedHashSet: © Copy all the elements of ArrayList to LinkedHashSet. © Empty the ArrayList using clear) method, which will remove all the elements from the list. © Now copy all the elements of LinkedHashset to ArrayList 31) How to reverse ArrayList? To reverse an ArrayList, we can use reverse() method of Collections class, Consider the following example import java.util ArrayList; import java.util.Collection; import java.util.Collections; import java.util.terator, import java.util.List; |nps:iiwwjavalpoin comijava-colectonsnterview-questions swt‘arena, 1:58PM Java Colectons Interview Questions (2023) javatpoint public class ReverseArrayList { public static void main(String{] args) { List list = new ArrayList<>0; listadd(10); listadd(50); listadd(30); Iterator i = listiterator(); System.out printin("printing the list..." while(,hasNext() System.out printin(inextQ); } Iterator i2 = listiterator(); Collections.reverse(list); System.out printin("printing list in reverse order. (i2.hasNextQ) System.out printin(i2.nextQ); Output printing the list 10 printing list in reverse order 50 10 |nps:iiwwjavalpoin comijava-colectonsnteriew-questions‘2122, 1:58 PM Java Collections Interview Questions (2023) javatpoint 32) How to sort ArrayList in descending order? To sort the ArrayList in descending order, we can use the reverseOrder method of Collections class. Consider the following example. import java.util ArrayList; import java.util,Collection; import java.util.Collections; import java.util, Comparator, import java.util.|terator; import java.util.List; public class ReverseArrayList ( al] args) { List list = new Arraylist<>0; list.add(10); listadd(50); listadd(30); listadd(60); listadd(20); list.add(90); public static void main(St Iterator i = listiteratord; System.out printin("printing the list..."); while(ihasNext() { System.out printin(inextQ); Comparator cmp = Collections.reverseOrder(); Collections sort(list,cmp); System.out printin(’printing list in descending order. Iterator i2 = list.iterator(; while(i2.hasNext0) { |nps:ihwwjavalpoin comijava-cotectons-nteriew-questions ret‘2122, 1:5 PM Java Collections Interview Questions (2023) javatpoint System.out printin(i2.next0); Output printing the list 10 58 30 60 20 printing 1 90 in descending order. 68 50 30 20 33) How to synchronize ArrayList? We can synchronize ArrayList in two ways. © Using Collections synchronizedList) method © Using CopyOnWriteArrayList
34) When to use ArrayList and LinkedList? LinkedLists are better to use for the update operations w search operations. |nps:iiwwjavalpoin comijava-cotectonsnteriew-questions wet2122122, 11:54 PM Java Collections Interview Questions (2023) javatpoint
You might also like
Xtream IPTV Activation Code 2025
PDF
72% (64)
Xtream IPTV Activation Code 2025
18 pages
The Kama Sutra in 200 Positions
PDF
84% (114)
The Kama Sutra in 200 Positions
215 pages
Jouissance Club Livre
PDF
100% (5)
Jouissance Club Livre
258 pages
The Complete French Conjugation Course - Cover
PDF
100% (6)
The Complete French Conjugation Course - Cover
447 pages
DUNOD DCG 2 Droit Des Sociétés
PDF
94% (16)
DUNOD DCG 2 Droit Des Sociétés
497 pages
Vocabulaire Progressif Du Français Corrigés
PDF
100% (11)
Vocabulaire Progressif Du Français Corrigés
65 pages
200 Common French Verbs
PDF
80% (10)
200 Common French Verbs
3 pages
Complete French (Learn French With Teach Yourself)
PDF
92% (65)
Complete French (Learn French With Teach Yourself)
509 pages
Collins Easy Learning French Grammar (Gnv64)
PDF
97% (58)
Collins Easy Learning French Grammar (Gnv64)
162 pages
Easy French Step-by-Step PDF
PDF
100% (23)
Easy French Step-by-Step PDF
399 pages
Colloquial French - The Complete Course For Beginners (Colloquial Series) PDF
PDF
100% (12)
Colloquial French - The Complete Course For Beginners (Colloquial Series) PDF
287 pages
The Perfect French Self Study Guide
PDF
100% (5)
The Perfect French Self Study Guide
22 pages
Advanced French Grammar PDF
PDF
97% (35)
Advanced French Grammar PDF
717 pages
Vocabulaire Progressif Du Francais Debutant Complet 2015
PDF
97% (33)
Vocabulaire Progressif Du Francais Debutant Complet 2015
114 pages
Le Petit Prince
PDF
100% (16)
Le Petit Prince
57 pages
French Grammar Basic
PDF
60% (10)
French Grammar Basic
16 pages
Short Stories FR Intermediate PDF
PDF
100% (7)
Short Stories FR Intermediate PDF
185 pages
365 Days of French Expressions Without Audio
PDF
100% (3)
365 Days of French Expressions Without Audio
237 pages
French Made Simple
PDF
93% (14)
French Made Simple
196 pages
French Foundations Master The Basics in Two Weeks (Olly Richards)
PDF
100% (7)
French Foundations Master The Basics in Two Weeks (Olly Richards)
155 pages
Core Java Interview Questions
PDF
0% (1)
Core Java Interview Questions
4 pages
Mastering Concurrency Programming Java 8 Ebook B012o8s89k PDF
PDF
No ratings yet
Mastering Concurrency Programming Java 8 Ebook B012o8s89k PDF
5 pages
French Workbook
PDF
100% (10)
French Workbook
288 pages
Infinitive: Simple Past
PDF
100% (14)
Infinitive: Simple Past
4 pages
Le Français en Images
PDF
91% (11)
Le Français en Images
86 pages
233 Complete French Grammer - Sample
PDF
82% (11)
233 Complete French Grammer - Sample
20 pages
A Definitive Guide To French Verbs
PDF
86% (7)
A Definitive Guide To French Verbs
106 pages
Collections Interview Questions
PDF
No ratings yet
Collections Interview Questions
7 pages
Interview Question Collection Framework PDF
PDF
No ratings yet
Interview Question Collection Framework PDF
13 pages
Java
PDF
100% (3)
Java
119 pages
Core Java Interview Question
PDF
No ratings yet
Core Java Interview Question
5 pages
Spring Interview Questions - Javatpoint
PDF
No ratings yet
Spring Interview Questions - Javatpoint
15 pages
Web Services Notes
PDF
No ratings yet
Web Services Notes
36 pages
Corejava - 24 11 2015
PDF
No ratings yet
Corejava - 24 11 2015
390 pages
How To Write Clean Java Code PDF
PDF
No ratings yet
How To Write Clean Java Code PDF
1 page
Java by Nageswara Rao
PDF
100% (1)
Java by Nageswara Rao
23 pages
JDevelopers Guide - IBM Java Interview Questions For 3-8 Year Experience
PDF
No ratings yet
JDevelopers Guide - IBM Java Interview Questions For 3-8 Year Experience
3 pages
Java 11 Notes
PDF
No ratings yet
Java 11 Notes
11 pages
Top 100 Java Interview Questions and Answers 2023
PDF
No ratings yet
Top 100 Java Interview Questions and Answers 2023
43 pages
Struts Spring Hibernate Tutorial
PDF
100% (1)
Struts Spring Hibernate Tutorial
83 pages
Adv - Java Means Durga Sir... : Durgasoft, Plot No: 202, Iind Floor, Huda Maitrivanam, Ameerpet, Hyderabad-500038
PDF
No ratings yet
Adv - Java Means Durga Sir... : Durgasoft, Plot No: 202, Iind Floor, Huda Maitrivanam, Ameerpet, Hyderabad-500038
35 pages
Java Collection Interview Questions
PDF
No ratings yet
Java Collection Interview Questions
3 pages
Java Interview Questions For 2 Years Experienced
PDF
No ratings yet
Java Interview Questions For 2 Years Experienced
8 pages
Inner Class DurgaSoft
PDF
No ratings yet
Inner Class DurgaSoft
20 pages
ArrayList Metode Java Programiranje
PDF
No ratings yet
ArrayList Metode Java Programiranje
2 pages
Struts Interview Questions by Satya Das - Q
PDF
No ratings yet
Struts Interview Questions by Satya Das - Q
3 pages
Array Interview Question
PDF
No ratings yet
Array Interview Question
17 pages
Interview Questions On JAVA
PDF
No ratings yet
Interview Questions On JAVA
32 pages
Java Interview Preparation
PDF
No ratings yet
Java Interview Preparation
35 pages
Java Faqs
PDF
No ratings yet
Java Faqs
122 pages
Java Collections Framework PDF
PDF
No ratings yet
Java Collections Framework PDF
62 pages
JAVA-Important Interview Questions
PDF
100% (1)
JAVA-Important Interview Questions
6 pages
100 Most Asked Java Interview QnA
PDF
No ratings yet
100 Most Asked Java Interview QnA
15 pages
Java Titbits
PDF
No ratings yet
Java Titbits
24 pages
Java Questionnaire
PDF
No ratings yet
Java Questionnaire
2 pages
File
PDF
No ratings yet
File
263 pages
100 Core Java Interview Questions PDF
PDF
No ratings yet
100 Core Java Interview Questions PDF
25 pages
Core Java
PDF
No ratings yet
Core Java
407 pages
Project Round Java QuestionAnswer
PDF
No ratings yet
Project Round Java QuestionAnswer
7 pages
Volume 2 Final
PDF
No ratings yet
Volume 2 Final
199 pages
Inner Class by Durga Sir
PDF
No ratings yet
Inner Class by Durga Sir
22 pages
JAva Interview
PDF
No ratings yet
JAva Interview
13 pages
1.1 Private Methods in Interfaces PDF
PDF
No ratings yet
1.1 Private Methods in Interfaces PDF
7 pages
Java Interview Questions - Subscribe To FREE & Exclusive Career Resources at
PDF
No ratings yet
Java Interview Questions - Subscribe To FREE & Exclusive Career Resources at
11 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
110 pages
Interview Questions: Etiam Sit Amet Est
PDF
No ratings yet
Interview Questions: Etiam Sit Amet Est
29 pages
General Questions: 1. What Is Java?
PDF
100% (1)
General Questions: 1. What Is Java?
125 pages
1.1 Try With Resources Enahancements PDF
PDF
No ratings yet
1.1 Try With Resources Enahancements PDF
6 pages
Java Interview Questions: Difference Between Procedure Oriented and Object Oriented Programming Language?
PDF
No ratings yet
Java Interview Questions: Difference Between Procedure Oriented and Object Oriented Programming Language?
62 pages
Java 8
PDF
100% (1)
Java 8
47 pages
Struts Questions
PDF
No ratings yet
Struts Questions
8 pages
69 Spring Interview Questions and Answers - The ULTIMATE List (PDF Download)
PDF
No ratings yet
69 Spring Interview Questions and Answers - The ULTIMATE List (PDF Download)
12 pages
Java Collection Interview Questions
PDF
No ratings yet
Java Collection Interview Questions
4 pages
Java Interview Questions
PDF
100% (1)
Java Interview Questions
3 pages
133 Core Java Interview Questions Answers From Last 5 Years - The MEGA List
PDF
No ratings yet
133 Core Java Interview Questions Answers From Last 5 Years - The MEGA List
20 pages
Spring Security
PDF
No ratings yet
Spring Security
21 pages
JSP Interview Questions and Answers
PDF
No ratings yet
JSP Interview Questions and Answers
7 pages
Junit - Testing Framework For Java: Types of Unit Testing
PDF
No ratings yet
Junit - Testing Framework For Java: Types of Unit Testing
24 pages
4th (Java Collections Interview Questions (2022) - Javatpoint)
PDF
No ratings yet
4th (Java Collections Interview Questions (2022) - Javatpoint)
22 pages
Java Collections Interview - 4
PDF
No ratings yet
Java Collections Interview - 4
15 pages
Java Collections Interview Questions
PDF
No ratings yet
Java Collections Interview Questions
14 pages
Java3
PDF
No ratings yet
Java3
22 pages
Java Collections Interview Questions
PDF
No ratings yet
Java Collections Interview Questions
11 pages
Formal Methods For Software Engineering Languages, Methods, Application
PDF
No ratings yet
Formal Methods For Software Engineering Languages, Methods, Application
537 pages
JDBC Interview Questions
PDF
No ratings yet
JDBC Interview Questions
22 pages
Connection
PDF
No ratings yet
Connection
6 pages
Java Runtime Class
PDF
No ratings yet
Java Runtime Class
9 pages
Java Multithreading and Concurrency Interview
PDF
No ratings yet
Java Multithreading and Concurrency Interview
31 pages
Daemon Thread in Java
PDF
No ratings yet
Daemon Thread in Java
8 pages
C'est-A-Dire - Advanced French Conversation PDF
PDF
100% (10)
C'est-A-Dire - Advanced French Conversation PDF
316 pages
Colloquial French Grammar
PDF
95% (19)
Colloquial French Grammar
257 pages
Language Hacking French (Learn How To Speak French Book)
PDF
100% (7)
Language Hacking French (Learn How To Speak French Book)
622 pages
French Grammar
PDF
100% (33)
French Grammar
368 pages
Easy French - 2 Books in 1 French Language + Short Stories For Beginners. A Complete Step-By-step Guide To Learn and Speak French Quick and Easy Starting From Zero
PDF
100% (3)
Easy French - 2 Books in 1 French Language + Short Stories For Beginners. A Complete Step-By-step Guide To Learn and Speak French Quick and Easy Starting From Zero
230 pages