Skip to main content

Posts

Showing posts from November, 2018

Difference between HashMap, LinkedHashMap and TreeMap

 LinkedHashMap is an implementation of java.util.Map interface with predictable iteration order (the order of insertion) i.e. LinkedHashMap will iterate in the order in which the entries were put into the map. LinkedHashMap implementation differs from HashMap in the way that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map. The insertion order is not affected if a key is re-inserted into the map. Performance of LinkedHashMap is slightly below than that of HashMap, due to the added expense of maintaining the linked list. The other two important implementations of Map interface are java.util.HashMap and java.util.TreeMap. They offer mostly the same functionality. The most important difference is the order in which iteration through the entries will happen. HashMap makes no guarantee about the order. The order can even change completely when ne

Implement singly linked list in java

One disadvantage of using arrays to store data is that arrays are static structures and therefore cannot be easily extended or reduced to fit the data set. Arrays are also expensive to maintain new insertions and deletions. In this article we take a look at another data structure called Linked Lists that addresses some of the limitations of arrays. We will see how to implement singly linked list in java, you can also watch the following video for better understanding of data structure A linked list is a linear data structure where each element is a separate object. It is one of the most used data structure. In singly linked list, Node has data and pointer to next node. It does not have pointer to the previous node. Last node ‘s next points to null, so you can iterate over linked list by using this condition. Node for linked list can be presented as below: // A simple Java program to introduced single linked list public class LinkedListexercise2 { N

Java data structures

A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. This video is designed  to help you get started with java data structures some popular linear data structures that  are explained includes  Array, Array List,  Linked List, Stack and Queue.