Core java
06 DecemberDifference between replace() and replaceAll() in java
In this post, we will see difference between String’s replace() and replaceAll() methods in java. [toc] String’s replace() and replaceAll() both replace all occurences in the String. String’s replace() takes either two chars or two CharSequences as arguments and it will replace all occurrences of char or String but replaceAll() method takes regex String as […]
18 NovemberConvert LocalDateTime to Timestamp in Java
In this post, we will how to convert LocalDateTime to Timestamp . [toc] Before learning how to convert localdatetime to timestamp, let us learn about LocalDateTime and Timestamp, and understand the importance of this conversion. LocalDateTime LocalDateTime was introcuded in Java 8. LocalDateTime can be imported time package: import java.time.LocalDateTime; LocalDateTime is an immutable object […]
12 OctoberJava 9 JShell tutorial
The Java JShell is a command-line tool that is introduced in Java 9 version. It helps to execute/test Java statements in a single line. [toc] It is based on REPL (Read Evaluate Print Loop) that reads a code statement, execute that and print the output, statement after statement. It reads the statement and immediately shows […]
11 OctoberJava 9: Stream API Improvements
In Java 9, following methods are added to Stream interface of stream package. These methods are default and static. [toc] The takeWhile() Method This method is included in Stream interface and used to collect the elements into a stream. It takes all the elements till the condition specified as predicate. For example, we want to […]
09 OctoberFind first and last digit of a number
In this article, we are going to find first and last digit of a number. To find first and last digit of any number, we can have several ways like using modulo operator or pow() and log() methods of Math class etc. [toc] Let’s see some examples. Before moving to example, let’s first create an […]
09 OctoberInitialize 2D array in Java
In this article, we will learn to initialize 2D array in Java. The array is a data structure that is used to collect a similar type of data into contiguous memory space. An array can be a single-dimensional or multidimensional. An array that has 2 dimensions is called 2D or two-dimensional array. There are several […]
03 OctoberHappy Number program in Java
In this article, we are going to learn to find Happy Number using Java. Let’s first understand, what is Happy Number? [toc] What is a Happy Number? A number which leaves 1 as a result after a sequence of steps and in each step number is replaced by the sum of squares of its digit. […]
02 OctoberInitialize ArrayList with values in Java
In this article, we will learn to initialize ArrayList with values in Java. ArrayList is an implementation class of List interface in Java. It is used to store elements. It is based on a dynamic array concept that grows accordingly. We can Initialize ArrayList with values in several ways. Let’s see some of them with […]