• 25 February

    hash and indexFor method in HashMap

    Java HashMap: 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 and values Difference between HashMap and HashSet Difference between HashMap and Hashtable How to iterate over HashMap Target AudienceThis post is for the people who already have […]

  • 09 June

    How to find length/size of Arraylist in java

    In this tutorial, we will see how to find length/size of Arraylist in java. You can use ArrayList’size() method to calculate size of ArrayList. Let’s understand it with the help of Simple example. [crayon-6143298ced0eb280917973/] When you run above program, you will get below output: Size of Country List is: 4 [India, China, Bhutan, Nepal] Size […]

  • Java Collections interview questions
    12 April

    Java Collections interview questions and answers

    In this post, I am going to share some of logical java Collections interview questions which will help to understand Collections concepts better. For an extensive list of java programs, please go to Java interview programs. Question 1: What can be output of below code : [crayon-6143298cedef0256503316/] options are :  A)France France India B)India India […]

  • 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-6143298cf0c3d374100684/] When you run above program, you will get following output: [crayon-6143298cf0c49898614889/] Please go through java […]

  • 01 May

    How to sort HashMap in java by keys and values

    HashMap does not preserve order of element but what if you want to sort it by keys or values. In this post, we will see how to sort HashMap by keys or values. Java HashMap tutorial: HashMap in java HashMap internal working hash and indexfor method in HashMap hashcode and equals in java sort HashMap […]

  • 03 June

    Convert HashMap to ArrayList in java

    In this post, we will see how to convert HashMap to ArrayList in java. Many times, you need to store keys or values into ArrayList or Store HashMap’s Node objects in ArrayList. HashMap and ArrayList both are the most used data structure in java and both have different Hierarchy. Here are the ways to convert […]

  • 12 September

    Difference between Iterator and ListIterator in java

    In this post, we will see difference between Iterator and ListIterator in java. They are both used for traversal but it is good to point out differences between them. Iterator vs ListIterator: Parameter Iterator ListIterator Traversal Iterator can be used to traverse List,set, Queue ListIterator can be used to traverse only List. Traversal direction Iterator can […]

  • 17 February

    Difference between HashMap and HashSet in java

    One of the common interview question is “What is difference between HashMap and HashSet”..Before we actually see differences,let me give you brief introduction of both. Java HashMap: 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 and values […]