Java 8 – Optional class in detail
BenchResources.Net
by SJ
9M ago
In this article, we will discuss Optional class in detail and understand why it is needed/introduced in Java 1.8 version and how to avoid/handle (or to get rid of) the infamous NullPointerException which comes under the umbrella of Runtime Exception 1. Optional class : This is the new class introduced in Java 1.8 version to handle/avoid the infamous NullPointerException swiftly but altogether NullPointerException can’t be avoided So, what is Optional class in Java 1.8 and why it is needed ? It is a wrapper class for the actual object or in other words container for the actual object This way ..read more
Visit website
Java 8 – How to Reverse a String in place ?
BenchResources.Net
by SJ
9M ago
In this article, we will see how to reverse a String in place using traditional & Java 8 Stream approaches 1. Traditional approach : Here, we will create a StringBuilder object with the given input String after trimming for any leading or trailing white-spaces Iterate through the string length for reversing the string by swapping approach Finally, test the reverse program with different set of input strings like odd length string even length string leading white-spaces trailing white-spaces leading & trailing white-spaces null empty string empty string with white–spaces ReverseStr ..read more
Visit website
Java 8 – How to find common & uncommon elements from 2 Lists ?
BenchResources.Net
by SJ
9M ago
In this article, we will discuss how to find and print common & uncommon elements from 2 Lists (or ArrayList) There are different ways to find common & uncommon elements from 2 List objects but here we will use Streams API introduced in Java 1.8 version Nowadays, this become one of the favorite interview question for the Interviewer at the fresher & intermediate levels 1. Find Uncommon elements : Few assumption from before proceeding further, First List contains more elements when comparing with second List Second list is sub-set of First List FindUncommonElementsFrom2ListUsingJa ..read more
Visit website
Java 8 – How to sort HashMap by its Values first and then by its Keys ?
BenchResources.Net
by SJ
9M ago
In this article, we will discuss how to sort a HashMap by its Values first and then by its Keys 1. Sorting HashMap by Value first and then by Key : Here, Map Values will be sorted first in decreasing-order and then by Keys in decreasing-order While sorting if there are 2/more same Map Values then sort according to Keys SortHashMapByValuesAndThenByKeys.java package in.bench.resources.find.duplicate.count; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Collectors; public class SortHashMapByValuesAndThenByKeys { public static ..read more
Visit website
Java 8 – Find duplicate count from Integer arrays ?
BenchResources.Net
by SJ
10M ago
In this article, we will discuss how to find the desired result from the Integer[] arrays for the problem statement given below 1. Problem statement : For the given integer array[] find the duplicate count in the specified-order below, Highest count of duplicate-number should come first i.e.; decreasing-order of duplicate count If there are 2 or more duplicate-number with same count then duplicate-number with higher-value should come first i.e.; again decreasing-order of duplicate numbers If there are 2 or more duplicate-number with count as 1 then duplicate-number with highest-value should o ..read more
Visit website
Java 8 – Find employee count in each department ?
BenchResources.Net
by SJ
10M ago
In this article, we will discuss how to find employee count in every department using Java 8 Stream API Find employee count in each department : Lets define employee class with 2 attributes namely – name department they belongs to Employee.java package in.bench.resources.find.duplicate.count; public class Employee { // member variables private String name; private String department; // 2-arg parameterized constructor public Employee(String name, String department) { super(); this.name = name; this.d ..read more
Visit website
Java – How to check if a String is an Integer ?
BenchResources.Net
by SJ
11M ago
In this article, we will discuss how to check if a String is an Integer or not using different String literals Check String is an Integer : Integer.parseInt(str) method converts the given String into an Integer – Returns the number, if it contains only numbers/digits Throws NumberFormatException, if it contains alphabets/letters CheckStringIsInteger.java package in.bench.resources.string.operation; public class CheckStringIsInteger { public static void main(String[] args) { // string literal String str1 = "12345"; String str2 = "a1 ..read more
Visit website
Java – Difference between start() and run() methods of Thread
BenchResources.Net
by SJ
1y ago
In this article, we will discuss 2 important methods of Thread class – start() & run() 1. Thread methods : There are several methods in Thread class, let’s focus on 2 important methods – run() If the invoking thread was constructed using a separate Runnable run object, then that Runnable object‘s run method is called; otherwise, this method does nothing and returns start() Causes the invoking thread to begin execution; the Java Virtual Machine (JVM) calls the run method of invoking thre ..read more
Visit website
Java – Important methods and constructors of a Thread class
BenchResources.Net
by SJ
1y ago
In this article, we will discuss important methods and constructors of a Thread class 1. Thread : Thread is a separate flow of execution in a program/process Threads are light–weight processes or smallest unit of work in a process Creating a Thread or spawning a new Thread means allocating a separate independent flow of execution in a process So, in a process we can create as many as Threads required for the process/program o ..read more
Visit website
Java – Thread Scheduler
BenchResources.Net
by SJ
1y ago
In this article, we will discuss Thread scheduler and the role it plays in scheduling in detail 1. Thread Scheduler : It is the part of JVM which is responsible to schedule Threads In other words, Thread Scheduler decides which – thread should get the opportunity to run/execute in CPU/processor thread should wait in the queue to get its opportunity If there are multiple threads waiting for their opportunity to run/execute then Thread Scheduler is the one which allocates CPU/processor for some thread making other threads to wait in the queue depending on the below factors – Thread Priority ..read more
Visit website

Follow BenchResources.Net on FeedSpot

Continue with Google
Continue with Apple
OR