Skip to main content

Posts

Showing posts from January, 2020

HashMap in Java

HashMap in Java In this article, we are going to learn about the most important class of Java known as HashMap. HashMap in java is the most used map interface and it is used in our regular or day-to-day programming practices.
What is HashMap in java? Lets first start with basic definition of HashMap,
HashMap is a map which store key-value pair, where each key is mapped with a value.
HashMap defined in java.util package and implements map interface which provides functionalities to perform basic operation like store, retrieve, size of the map etc. It is a part of Java Collection Framework. Time complexity of HashMap in Java? : Time complexity to store and retrieve data from the HashMap is O(1) in the Best Case. But it can be O(n) in the worst case and after the changes made in Java 8 the worst case time complexity can be O(log n) atmost. Internal working of HashMap in java HashMap maintains an array of the buckets, where each bucket is a linked-list and the linked list is a list of…

How HashMap works internally in java

How Hashmap works Internally in Java In this article, we are going to see how HashMap internally works in java. Also, we will have a look at what Java 8 made changes on the internal working of Hashmap to make it faster. What is Hashmap and Hashing in java? How Hashmap works Internally in Java is majorly dependent upon the Hashing Principle. So, Before going to learn how HashMap works internally in java, lets first understand what is HashMap and hashing. HashMap : A HashMap is a map used to store mappings of key-value pairs. Also, it works on the Principle of Hashing. To know more about the HashMap, visit this article: HashMap in Java Hashing Principle : Simply, Hashing is a method used to produce an integer value from an object and this integer value known as the hash value. In HashMap, the key object is used for Hashing.
Internal Struture of the HashMap in java For internal working of HashMap, HashMap maintains an array of bucket, each bucket is a linked-list and linked list is a li…

Functional Interface in Java

Functional Interface in Java In this article, we are going to see what is a Functional Interface in Java, Also we are going to have a look on how we can create and use functional interface in java Content of this articleWhat is Functional Interface in Java?How to Instantiate Functional Interface in Java?New Functional Interface introduced in Java 8 What is Functional Interface in Java?Functional Interface in Java is an interface which contains only one abstract method. Let see an example of Functional Interface in Java. @FunctionalInterface interface BookConstraint{ boolean test(Book book); }Note : Functional interface in Java can be instantiate by lambda expressions, method references, or anonymous class. We will see later how we can instantiate the Functional Interface in java later in this post. @FunctionalInterface Annotation In the above example, the interface is marked with @FunctionalInterface annotation. The @FunctionalInterface annotation (Introduced in Java 8) can be use…

Lambda Expression Java

How to use Lambda Expression Java In this article, we are going to see how we can use Lambda Expression Java. We will see how lambda expressions make our code so much easy to write and read. It helps to remove unnecessary coding from our program. Basically, Lambda expression makes our code more focused towards what to do not how to do. What is Lambda Expression Java A Lambda Expression can be considered as a brief description of a method or function without a name. A method or function in java has name, parameters or arguments, return type and body Similarly a lambda expression in java also consists of arguments, body and return type but without the name.
Let's have a first look of lambda expression in java: // First look of Lambda expression in java (Book book) -> { return book.getTitle().contains("Java"); }; Also, look at equivalent method or function representation in java: boolean check(Book book) { return book.getTitle().contains("Java"); }; Don&#…