Java8 lambda comparator Realtime Examples
In this tutorial, we will learn about using comparators with Lamda. Comparators are extensively used in collections to sort objects link users, employees, orders etc. In Java 8, comparators can…
In this tutorial, we will learn about using comparators with Lamda. Comparators are extensively used in collections to sort objects link users, employees, orders etc. In Java 8, comparators can…
Comparable and Comparator are two Java interfaces that allow objects to be compared and sorted. Comparable Comparable is a functional interface that is implemented by a class to define its…
In this post, we will see the java is pure functional programming language or not. Java is not a purely functional programming language support functional programming concepts with help of…
Problem: Given array of size ‘n’ and left rotate k times Input : [1,2,3,4,5,6,7], K=3 Left Rotate 1: 2,3,4,5,6,7,1 Left Rotate 2: 3,4,5,6,7,1,2 Left Rotate 3: 4,5,6,7,1,2,3 Solution: Reverse the…
Problem : Given of size ‘n’ and a values ‘k’ around which we need to right rotate the array. Array: [1,2,3,4,5,6,7], K = 3 Rorate1: 7,1,2,3,4,5,6 Rotate2: 6,7,1,2,3,4,5 Rotate3: 5,6,7,1,2,3,4 Solution…
In this post, we will see Valid Parenthesis with stack. This solution uses a counter to keep track of the balance of parentheses. Whenever an opening parenthesis is encountered, the…
This is one of the most common datastructure interview questions and to validate parenthesis. Examples of valid parentheses: (()){}{} Examples of Invalid parentheses : ({) or {(((()))) Problem: Given a…
The writeReplace and readResolve methods in Java allow you to customize the serialization and deserialization process of an object. writeReplace is called during the serialization process. This method provides an…
Example Custom serialization in Java: import java.io.*; class Person implements Serializable { private static final long serialVersionUID = 1L; private String name; private int age; public Person(String name, int age)…
Circular references during serialization in Java can cause StackOverflowError or OutOfMemoryError exceptions. This happens because a circular reference creates a loop in the object graph that the serialization process tries…