Most Asked Java Collection Framework Interview Questions and Answers | Code Decode | Part 2

Описание к видео Most Asked Java Collection Framework Interview Questions and Answers | Code Decode | Part 2

In this video of code decode we have covered most asked collection framework interview questions

Udemy Course of Code Decode on Microservice k8s AWS CICD link:
https://openinapp.co/udemycourse

Course Description Video :
https://yt.openinapp.co/dmjvd

Collection Interview Questions part - 1
   • Java collections framework interview ...  

00:09 How does LinkedList is implemented in Java, is it a Singly or Doubly linked list?
LinkedList in Java is a doubly linked list.

00:37 When to use ArrayList and LinkedList?
LinkedLists are better to use for the update operations whereas

ArrayLists are better to use for the search operations.

02:36 What is the difference between the HashMap, TreeMap and LinkedHashMap?

The next question in collection interview questions and answer is :

06:10 What is a priority queue in Java?
A priority queue in Java is an abstract data type similar to a regular queue or stack data structure but has a special feature called priority associated with each element.

In this queue, a high priority element is served before a low priority element irrespective of their insertion order. The PriorityQueue is based on the priority heap.

The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used.

07:06 Can you use any class as a Map key?
The class overriding the equals() method must also override the hashCode() method

The class should adhere to the rules associated with equals() and hashCode() for all instances

The class field which is not used in the equals() method should not be used in hashCode() method as well

The best way to use a user-defined key class is by making it immutable. It helps in caching the hashCode() value for better performance. Also if the class is made immutable it will ensure that the hashCode() and equals() are not changing in the future.




09:34 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.


10:31 How to traverse or loop over a Map in Java
1. Iterating or looping map using Java 5 foreach loop

2. Iterating Map in Java using KeySet Iterator

3. Looping HashMap in Java using EntrySet and Java 5 for loop

4. Iterating HashMap in Java using EntrySet and Java iterator

14:55 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.


16:40 How is WeakHashMap differs from other HashMap?

WeakHashMap is a HashMap, with keys that are of a WeakReference type.

An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use, meaning that there is no single Reference that point to that key. When the garbage collection (GC) process discards a key, its entry is effectively removed from the map, even though it is associated with WeakHashMap. i.e Garbage Collector dominates over WeakHashMap.


20:48 What are best practices related to Java Collections Framework


Most Asked Core Java Interview Questions and Answers:    • Core Java frequently asked Interview ...  
Advance Java Interview Questions and Answers:    • Advance Java Interview Questions  

Java 8 Interview Questions and Answers:    • Java 8 Interview Questions(New Features)  

Hibernate Interview Questions and Answers:
   • Hibernate Interview Questions Java  

Spring Boot Interview Questions and Answers:
   • Advance Java Interview Questions  

Angular Playlist:    • Angular Course Introduction || Angular 8  
SQL Playlist:    • SQL Interview Questions and Answers  

GIT:    • GIT  

Subscriber and Follow Code Decode
Subscriber Code Decode: https://www.youtube.com/c/CodeDecode?...
LinkedIn :   / codedecodeyoutube  
Instagram:   / codedecode25  

#collections #java #codedecode

Комментарии

Информация по комментариям в разработке