When working with Iterable in Java, sometimes you need to remove duplicated elements before processing them. Java provides a powerful Stream API to perform that. This tutorials shows some Java Stream Distinct to remove...
Tagged: Java
Java Stream distinct by property
Java introduced the powerful Stream API to support functional-style operations. This tutorial will show how to find distinct elements of Stream by property or attribute. Find distinct elements natively Returns a stream consisting of...
Jaxb marshal to String
When working with JAXB, sometimes you want a String representation of your XML. This tutorial will show how to JAXB marshal to String. Below the code of marshaling to String.
1 2 3 4 5 6 7 8 9 |
ClassWeWantToMarhsall cc = ...; JAXBContext context = JAXBContext.newInstance(ClassWeWantToMarhsall.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter sw = new StringWriter(); m.marshal(cc, sw); String result = sw.toString() |
Rename Spring Boot application.properties configuration file
By default, Spring Boot will look for your externalized properties in a file named application.properties located in one of the following folders : classpath root in the package /config in classpath in the current...
5 ways to convert Inputstream to String in Java
This tutorial shows 5 different ways to convert InputStream to String in Java.
3 ways to solve Fatal error compiling: invalid target release in Maven build
Problem You may encounter the following error when running a Maven build: Fatal error compiling: invalid target release: <JDK_VERSION> Solution Below three ways to solve the problem: Adding the environment variable JAVA_HOME Using Maven...
Delete files with extension in Java
Sometimes you need to delete files having certain extension within a directory. Two approach are possible, you can either list all files within the directory and check their extension before deletion or list only files having the extension using...
4 ways to copy file in Java
There is several ways to copy file from one location to another. 4 ways will be shown here : Writing a InputStream to an OutputStream Using FileChannel Using java.nio.file.Files Using Apache Commons IO FileUtils
3 ways to append content to file in Java
There are several ways to append content to an existing file in Java. Below three ways to do it : Using FileWriter Using java.nio.file.Files Using Apache Commons IO FileUtils 1- Using FileWriter JDK 1.4+ Since...
Java LDAP SSL authentication
In this article, we will see how to make a secured LDAP authentication using Java. First thing to do is importing the trust certificate to Java keystore. The default java keystore is named cacerts and...