Core java
- 07 March
Random Number Between 1 and 100 in Java
TL;DR To generate random number between 1 and 100 in java, you can use Math.random() method. [crayon-673f62a331691369478332/] Output: Random number between 1 and 100: 26 Math.random Java between 1 and 100 Java provides the Math class to perform all sorts of mathematical operations. The class also has a method named random() that produces pseudo-random numbers […]
- 04 March
Check if Array Is Empty in Java
In this post, we will see how to check if array is empty in Java. The arrays are a data structure that facilitates storing multiple instances of data together in contiguous memory locations. This article discusses different cases when an array is considered to be empty in Java. It also discusses methods to check, for […]
- 22 February
[Fixed] java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
In this post, we will see how to fix java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList. ClassCastException is runtime exception which indicate that code has tried to cast an object to a subclass which is not an instance. Reason for java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList Although static method Arrays.asList() returns List, it returns […]
- 21 February
[Fixed] java.util.HashMap$Values cannot be cast to class java.util.List
In this post, we will see how to fix error java.util.HashMap$Values cannot be cast to class java.util.List. Why HashMap values cannot be cast to list? HashMap values returns java.util.Collection and you can not cast Collection to List or ArrayList. It will throw ClassCastException in this scenario. Let’s understand with the help of example: [crayon-673f62a331f0c073423436/] Output: […]
- 20 February
Format Number with Commas in Java
In this post, we will see how to format number with commas in java. How To Add Commas to Number in Java There are multiple ways to format number with commas in java. Let’s go through them. 1. Using DecimalFormat DecimalFormat can be used by providing formatting Pattern to format number with commas in java. […]
- 20 February
[Fixed] Unable to obtain LocalDateTime from TemporalAccessor
In this article, we will see how to fix Unable to obtain LocalDateTime from TemporalAccessor in Java 8. Unable to obtain LocalDateTime from TemporalAccessor : Reason You will generally get this error, when you try to convert String to LocalDateTime and Formatted String does not have time related information. Let’s understand with the help of […]
- 17 February
Convert LocalDate to Instant in Java
In this article, we will see how to convert LocalDate to Instant in Java. Java LocalDate to Instant Instant class provides an instantaneous point in time. When you want to convert LocalDate to Instant, you need to provide time zone. Using toInstant() wth ZoneId ZoneDateTime’s toInstant() method can be used to convert LocalDate to Instant. […]
- 17 February
Convert Instant to LocalDate in Java
1. Overview In this article, we will see how to convert Instant to LocalDate in java. An Instant represents a specific moment in time in the UTC timezone, whereas a LocalDate represents a date without time or timezone information. The challenge is to extract the date part from an Instant object and represent it as […]
- 17 February
Convert String to LocalDateTime in Java
In this article, we will see how to convert String to LocalDateTime in Java. LocalDateTime class was introduced in Java 8. LocalDateTime represents local date and time without timezone information. It is represented in ISO 8601 format (yyyy-MM-ddTHH:mm:ss) by default. Java String to LocalDateTime To convert String to LocalDateTime in Java, LocalDateTime provides static method […]