Core java
20 SeptemberGet Unix Timestamp in Java
In this post, we will get unix timestamp in Java. As per wikipedia Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970. Unix time is standard way […]
20 SeptemberReturn ArrayList in Java
This article discusses cases of returning an ArrayList in Java from a method. An ArrayList in Java is a collection of elements of the same data type under a single variable name. In different cases, you can return an ArrayList from a method in Java. These cases are as given below. Returning ArrayList from a […]
19 SeptemberConvert Month Name to Number in Java
In this post, we will see how to convert Month name to number in Java. Please note that we will use first three letter of month name (First letter as capital) to convert it to Number. There are multiple ways to convert month name to number in java. Let’s go through. Using DateTimeFormatter and TemporalAccessor […]
19 SeptemberHow to Print 2D Array in Java
Introduction In this article, we get a look on How to print a 2D or Two Dimensional array in java. Arrays are one of the most useful data structures when it comes to data storage. Arrays provide random access to the elements via their index basing which makes both accessing and storing the most efficient. […]
19 SeptemberCount Number of Decimal Places in Java
In this post, we will see how to count number of decimal places in java. A Double can not have exact representation, you need to convert it to String to count number of decimal places in Java. There are multiple ways to count number of decimal places in java. Let’s go through them. Using String’s […]
19 SeptemberReturn Empty Array in Java
[toc] TL;DR To return empty Array in Java, you can use curly braces. public static String[] returnEmptyStringArray() { String[] emptyArray = {}; return emptyArray; } or public static String[] returnEmptyStringArray() { return new String[]{}; } 1. Introduction In this article, we will take a look on to How to return Empty array in java. We […]
18 September[Fixed] IllegalArgumentException: Bound must be positive
In this post, we will see how to fix IllegalArgumentException: Bound must be positive in java. You will generally get this exception while generating random numbers using Random.nextInt() method. If you pass bound as 0 or less than 0, then you will get the exception. Let’s understand with the help of example: package org.arpit.java2blog; import […]
17 SeptemberCreate List with One Element in Java
In this post, we will see how to create List with One Element in java.. Using Collections.singletonList() This is best way to create List with single element if you need an immutable List. package org.arpit.java2blog; import java.util.Collections; import java.util.List; public class CreateListWithSingleElementJavaCollections { public static void main(String[] args) { List list = Collections.singletonList("India"); System.out.println("List: "+list); […]
17 SeptemberReplace null with Empty String in Java
1. Introduction to the Problem Statement In Java development, handling null values effectively is crucial, especially when dealing with strings. A common requirement is to replace null strings with empty strings to avoid NullPointerException and maintain the flow of the application. If the given string is null, the output should be an empty string; otherwise, the […]