Tag Archives: collection framework

How to Remove Element from List In Java

Oracle Java

I tried to demonstrate how to remove element from List in Java. There might be possibility to asked this question by interviewer in different way in your interview. How to remove any element from List, or its implementation class ArrayList, Vector, LinkedList or CopyOnArrayList. In a day-to-day development, you can found the situation where you have to remove item from List , based on the matching of value. So, you can use the following way in your real life project. If you don’t know how to iterate element from list in java, first visit provided link to understand how to iterate over ArrayList.

Continue reading How to Remove Element from List In Java

Different way to iterate List in Java

Oracle Java
There are different way of traversal of ListArrayList, Vector object in java for getting its values. In day-to-day life, we almost use List with different flavor of created object like AraryList, Vector, LinkedList on every alternate day in java programming language, but way of iteration is different , its depend upon the requirement and the required thing in mind on that point of time.

Continue reading Different way to iterate List in Java

How to remove Entry from HashMap in Java

Oracle Java
Well, sometimes interviewer asked you , how to remove any Entry/record from Map, or its implementation class HashMap, Hashtable, LinkedHashMap or ConcurrentHashMap. In day-to-day development you can found the situation where you have to remove from Map best on the matching of key or value. So you can use the following way in your real life project. I prefer , if you don’t know how to iterate HashMap in java , first go through prior post to understand how to iterate over HashMap.
Continue reading How to remove Entry from HashMap in Java

Different way to iterate Map in Java

Oracle Java
There are different way of traversal of Map HashMap , ConcurrentHashMap object in java for getting key/value pair . In day-to-day life, we almost use Map (either get or put operation) on every alternate day in java programming language. But way of iteration is different , its depend upon the requirement and thing in mind on that point of time. Most of the time while iteration we don’t know the key and its value. we have to iterate over and best on that we usually process.
Continue reading Different way to iterate Map in Java

Difference Between HashMap and HashSet in Java

java-logoHashMap and HashSet is one of the most frequently asked interview question during any level of core java interview. Usually, Collection framework and multi-threading interview questions are mostly on demand for core java interview question.

Both HshMap and HashSet are integral part of Collection framework in java. These are most frequently used collection classes, it means , HashMap from Map , HashSet from Set and ArrayList from List in java.
Continue reading Difference Between HashMap and HashSet in Java

fail-fast iterator vs fail-safe iterator in Java

Oracle Java
When I first encounter with these terminology, some questions arise in my mind about fail-fast and fail-safe , in initial days. When we add anything while iterating we encounter ConcurrentModificationException, specially , when we delete element from collection while iterating using for-each loop of jdk 5. I hope every developer in their life must encounter ConcurrentModificationException. The concept of fail-safe terminology in java iterator is new. First introduced with Concurrent Collections in Java 5 e.g. ConcurrentHashMap and CopyOnWriteArrayList.
Continue reading fail-fast iterator vs fail-safe iterator in Java