Learn to compile regular expression into java.util.function.Predicate. This can be useful when you want to perform some operation on matched tokens.
Java 8 allows to refer method from class or object using class::methodName syntax. Learn about different types of available method references in java 8.
Using java 8 stream API, you can use stream.distinct() method to filter or collect all distinct elements from a collection. Let’s learn how to find distinct elements with java stream API.
In this example, we will learn to use java 8 APIs along with Files.list() and DirectoryStream to list all files present in that directory.
In this example, we will learn to watch a directory along with all sub-directories and files inside it, using java 8 WatchService API.
Java 8 code examples to write content into file. You may find examples of reading files using java 8 APIs in linked blog post. Write to file using BufferedWriter BufferedWriter is used to write text to a character or byte stream. Before printing the characters, it stores the characters in buffer and print in bunches. […]
Let’s see how you can convert from string to date in java 8. 1) Convert string to date in ISO8601 format By default, java dates are in ISO8601 format, so if you have any string which represent date in ISO8601 format then you can use LocalDate.parse() or LocalDateTime.parse() methods directly. 2) Convert string to date […]
Let’s see the example of joining array of String to produce single String. We may need this information many times during development specially while parsing contents out of JSON or XML. 1) Join String Array using String.join() method – Java 8 String.join() method has two flavors. i) join(CharSequence delimiter, CharSequence… elements) This method can be […]
In this tutorial, I am listing down 3 ways to know the difference between two dates in java. Fist way is to calculate using Jodatime API which was available even before java 8 release. Later 2 ways are using new Date Time API features available since java 8. Difference between dates before java 8 using […]
All of us must have encountered NullPointerException in our applications. This exception happen when you try to utilize a object reference which has not been initialized, initialized with null or simply does not point to any instance. NULL simply means ‘absence of a value’. Most probably, the Romans were only ones, who didn’t run into […]