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)
174 views
34 Java Collections Interview Questions
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
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)
174 views
34 Java Collections Interview Questions
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
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
Download
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? 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 ArrayList0; 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 Arraylist0; 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
Collection Framework in Java
PDF
100% (1)
Collection Framework in Java
14 pages
1.collections in Java - Javatpoint
PDF
No ratings yet
1.collections in Java - Javatpoint
18 pages
Interview Question Collection Framework PDF
PDF
No ratings yet
Interview Question Collection Framework PDF
13 pages
Java
PDF
100% (3)
Java
119 pages
ArrayList Metode Java Programiranje
PDF
No ratings yet
ArrayList Metode Java Programiranje
2 pages
Core Java Interview Question
PDF
No ratings yet
Core Java Interview Question
5 pages
Java As Object Oriented Programming Language: Unit IV
PDF
No ratings yet
Java As Object Oriented Programming Language: Unit IV
32 pages
How To Write Clean Java Code PDF
PDF
No ratings yet
How To Write Clean Java Code PDF
1 page
Spring Interview Questions
PDF
100% (1)
Spring Interview Questions
21 pages
Spring and Hibernate
PDF
No ratings yet
Spring and Hibernate
4 pages
Java Collection Interview Questions
PDF
No ratings yet
Java Collection Interview Questions
3 pages
JAVA-Important Interview Questions
PDF
100% (1)
JAVA-Important Interview Questions
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 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
Web Services Interview Questions
PDF
No ratings yet
Web Services Interview Questions
10 pages
1.1 Private Methods in Interfaces PDF
PDF
No ratings yet
1.1 Private Methods in Interfaces PDF
7 pages
Top 100 Java Interview Questions and Answers 2023
PDF
No ratings yet
Top 100 Java Interview Questions and Answers 2023
43 pages
SCJP Dumps
PDF
75% (4)
SCJP Dumps
24 pages
Java Collections Framework PDF
PDF
No ratings yet
Java Collections Framework PDF
62 pages
Collections in Java
PDF
100% (2)
Collections in Java
27 pages
Java PDF
PDF
No ratings yet
Java PDF
183 pages
Exception Handling Interview Questions
PDF
No ratings yet
Exception Handling Interview Questions
6 pages
Exercises On Collections
PDF
No ratings yet
Exercises On Collections
5 pages
Struts Spring Hibernate Tutorial
PDF
100% (1)
Struts Spring Hibernate Tutorial
83 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
110 pages
Core Java
PDF
No ratings yet
Core Java
407 pages
Java Titbits
PDF
No ratings yet
Java Titbits
24 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
Struts Questions
PDF
No ratings yet
Struts Questions
8 pages
1.1 Try With Resources Enahancements PDF
PDF
No ratings yet
1.1 Try With Resources Enahancements PDF
6 pages
JSP Interview Questions and Answers
PDF
No ratings yet
JSP Interview Questions and Answers
7 pages
Collection Framework
PDF
No ratings yet
Collection Framework
30 pages
Java Questions
PDF
0% (1)
Java Questions
9 pages
Inner Class by Durga Sir
PDF
No ratings yet
Inner Class by Durga Sir
22 pages
Web Services Notes
PDF
No ratings yet
Web Services Notes
36 pages
JAVA 1 Soln
PDF
No ratings yet
JAVA 1 Soln
98 pages
ArrayList in Java
PDF
No ratings yet
ArrayList in Java
3 pages
Java Interview Questions For 2 Years Experienced
PDF
No ratings yet
Java Interview Questions For 2 Years Experienced
8 pages
Angular Interview Questions
PDF
No ratings yet
Angular Interview Questions
13 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
Collection Fram Work in Java Interview Questions
PDF
No ratings yet
Collection Fram Work in Java Interview Questions
7 pages
1) What Is The Collection Framework in Java?
PDF
No ratings yet
1) What Is The Collection Framework in Java?
14 pages
Java Collections Interview Questions and Answers
PDF
No ratings yet
Java Collections Interview Questions and Answers
32 pages
Collection Interview Questions
PDF
No ratings yet
Collection Interview Questions
51 pages
16 Questions Related To Collection
PDF
100% (3)
16 Questions Related To Collection
6 pages
Top 50+ Java Collections Interview Questions (2024)
PDF
No ratings yet
Top 50+ Java Collections Interview Questions (2024)
44 pages
Chapter 5 Collection Framework Answers
PDF
No ratings yet
Chapter 5 Collection Framework Answers
6 pages
20 Java Collections Interview Questions: 1) What Is The Difference Between Arraylist and Vector?
PDF
No ratings yet
20 Java Collections Interview Questions: 1) What Is The Difference Between Arraylist and Vector?
5 pages
Collection Interview Notes
PDF
No ratings yet
Collection Interview Notes
14 pages
Java Collections Q&A
PDF
No ratings yet
Java Collections Q&A
65 pages
Top 50+ Java Collections Imp Interview Questions (2024)
PDF
No ratings yet
Top 50+ Java Collections Imp Interview Questions (2024)
54 pages
Java Collections Interview Questions (2022) - javatpoint
PDF
No ratings yet
Java Collections Interview Questions (2022) - javatpoint
12 pages
CollactionFramwork
PDF
No ratings yet
CollactionFramwork
194 pages
Java Collections
PDF
No ratings yet
Java Collections
4 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
Daemon Thread in Java
PDF
No ratings yet
Daemon Thread in Java
8 pages
Java Multithreading and Concurrency Interview
PDF
No ratings yet
Java Multithreading and Concurrency Interview
31 pages