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 […]
In java 8 learning series, we already learned about new way to read a file line by line using streams. Java 8 introduced one more good addition related to IO operations and that is Base64 support. I this post, we will learn about it. What is Base 64 encoding? When you have some binary data […]
In this post, I am giving example of a very useful task in day to day programming i.e. reading files line by line using java IO and perform some operations of lines. Before moving ahead, let me mention the file content which I will read in all examples in this post. I will read the […]