• 29 April

    TreeMap in java with examples

    TreeMap class implements Map similar to HashMap. Some important points about TreeMap: TreeMap implements Map interface and extends HashMap class. TreeMap is implemented using Red black tree based NavigableMap. TreeMap is ordered collection and store its elements in natural ordering of keys. Key which you would like to put in TreeMap must implement Comaparable interface or you can […]

  • 28 April

    LinkedHashMap in java

    LinkedHashMap is a Hashtable and linked list-based implementation of Map interface, with predictable insertion order. It maintains double linked list of all its entries, that’s how it differs from HashMap. Java LinkedHashMap Some points about LinkedHashMap LinkedHashMap implements Map interface and extends HashMap class. LinkedHashMap maintains insertion order, so when you will be able to […]

  • 04 May

    How HashMap works in java

    Most common interview questions are <code>How HashMap works in java</code>, “How get and put method of HashMap work internally”. Here I am trying to explain internal functionality with an easy example. [crayon-614328e54b5d1086981717-i/]  is one of the most used Collections in java.Rather than going through theory, we will start with example first, so that you will […]

  • 29 April

    HashMap in java

    HashMap is hash table based implementation of Map interface. It stores entry in key-value pairs. It maps keys to values. It is one of the most used Collection. Java HashMap HashMap implements Map an interface that maps a key to value. It is not synchronized and is not thread-safe. Duplicate keys are not allowed One […]

  • 26 February

    Difference between Comparator and Comparable in java

    CodeProject One of the common interview question is “What are differences between Comparator and Comparable”. or “How will you sort collection of employee objects by its id or name”.For that we can use two interfaces.i.e. Comparator and Comparable.Before we actually see differences,let me give you brief introduction of both. Comparable interface: Class whose objects to […]

  • 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 […]

  • 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-614328e54d17d468409537/] If any class implements comparable inteface then collection of that object can be sorted automatically using […]

  • 18 May

    ArrayList in java

    ArrayList in java is most common Collections data structure along with HashMap which we use very often. Why to choose ArrayList vs Array: Array is fixed length data structure If array is full , you can not add element to it, where as ArrayList in java can dynamically grow and shrink as per our need. […]