Java Collections
- 12 September
TreeSet in java
In this post, we will see TreeSet in java. Java TreeSet have following properties: It can contain only unique element. It stores objects in ascending order by default, It implements NavigableSet interface which extends SortedSet. When you put objects in TreeSet, it must implement Comparable interface. Lets understand it more with the help of example. […]
- 19 August
Java Timer example
Timer is an utility class which can be used to schedule tasks on specific time or repeatedly. Lets say, you are developing an banking application and there is need to process the data at 7 PM evening daily. You can easily schedule task using Timer class. For creating a task, you need to extends TimerTask […]
- 06 August
How to remove duplicates from ArrayList in java
In this post, we will see how to remove duplicate elements from ArrayList in java. There are many ways to do it. Some of them are: Using iterative approach Using HashSet (but does not maintain insertion order) Using LinkedHashMap Program: [crayon-6767d7ca7c87e330914189/] When you run above program, you will get following output: [crayon-6767d7ca7c882978791086/] Please go through java […]
- 25 June
How to iterate over Map or HashMap in java
In this post, we will see how  can we iterate a map in java. There are four ways of iterating over a map, HashMap or TreeMap. Java HashMap tutorial: HashMap in java How HashMap works in java hash and indexfor method in HashMap hashcode and equals method in java How to sort HashMap by keys […]
- 24 June
How to iterate a list in java
In this post, we will see how  can we iterate a list in java. There are four ways of iterating over a list. For loop For each loop(Java 5) While loop Iterator Below example will help you to understand, how to iterate list in java. I am taking custom object list to understand better 1. […]
- 17 June
Difference between ArrayList and LinkedList in java
One of the common interview question is “What is difference between ArrayList and LinkedList”.Before we actually see differences,let me give you brief introduction of both. ArrayList ArrayList is implementation of list interface. ArrayList is not synchonized(so not thread safe) ArrayList is implemented using array as internal data structure.It can be dynamically resized . LinkedList LinkedList […]
- 19 July
How HashSet works in java
In this post, we will see about Hashset in java Java HashSet: [crayon-6767d7ca7cb51655979873/] This is one of the frequently asked question in core java interview so in this post, we will see how HashSet works in java.We have already seen How hashMap works in java and also difference between HashMap and HashSet. Lets first see […]
- 18 June
Comparable in java
In this post, we will see how you can use comparable to sort list of objects in java. Comparable interface: Class whose objects to be sorted must implement this interface.In this,we have to implement compareTo(Object) method. For example: [crayon-6767d7ca7cccc417018262/] If any class implements comparable inteface then collection of that object can be sorted automatically using […]
- 17 June
Comparator in java
In this post, we will see how you can use comparator to sort list of objects in java. Comparator: When you want to sort the list of objects of a class,you can use Comparator interface. You don’t need to implement Comparator on the class whose objects need to be sorted. You can create a separate […]