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

preview_player
Показать описание
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:

Course Description Video :

Collection Interview Questions part - 1

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?

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

Hibernate Interview Questions and Answers:

Spring Boot Interview Questions and Answers:

Subscriber and Follow Code Decode

#collections #java #codedecode
Рекомендации по теме
Комментарии
Автор

16:35 for this we can use like that also :-public class Main {
public static void main(String[] args) {

ArrayList<Integer> al=new ArrayList<>();
al.add(1);
al.add(2);
al.add(3);
al.add(3);
Set<Integer> set=new HashSet<>();

Iterator<Integer> listIterator = al.iterator();
while (listIterator.hasNext()) {

Integer next = listIterator.next();
if(!set.add(next))
{
listIterator.remove();
}

}

set.clear();
System.out.println(al);
System.out.println(set);

}
}

anuragpanwar
Автор

Make a complete single vdo covering imp interview Questions on Oracle sql
...love your way of explaining the things in clear and concise way ❤️😊

ArpitSingh-wpyx
Автор

pure Gold🔥 Please being more sessions on collection

arpitsik
Автор

Mam ur teaching is fabulous
Make video on hibernate in deep
And spring and springboot, rest api

husenfakir
Автор

Firstly thanks for the videos. It helps immensely. Just wantrd to say, if you can increse the frequency of your videos it will help much.

arpitsik
Автор

The way you explained is simply super can you please make a single vedio and complete vedio for java 8 feactures instead of different different vedios make it single vedio

ganeshkumarroyal
Автор

I was about to request this video from you and you posted it. Thank you very much. I've been following for a quite a long time now, really appreciate the efforts you put in. Great content. Waiting for more🙂

AnilKumar-fbjg
Автор

Your explanation is so good, want to learn java 17
If you can make it's so helpful to us

dssomething
Автор

LinkedHashMap preserves the insertion order right .. while iterating the keyset or entryset then how does it maintain the insertion order?

dhrupeshpokiya
Автор

For treemap, do we have to implement comparator or comparable in the class (which is going to be key)?

sonalgupta
Автор

Thank you mam, can you please make videos on trees and graph also like one question on graph was asked in an interview -> there is 2 array given check if it is cyclic graph or not .

utkarshshukla