How to join multiple strings using append(), StringJoiner, String.join() in Java

In this tutorial we will see the difference between StringJoiner and String.join(). These were introduced into Java 8 version. The example we create here will show how to join multiple string objects or literals or list of strings using append(), StringJoiner, String.join() API. Situation may occur when you need to join multiple string literals or objects into one. You may also find a situation when you need to convert a list of strings or a collection of strings into csv(comma separated value) strings.

Continue

Read last n lines from a file using Java

Introduction Here I will show you how to read last n lines from a file using Java programming language. I am using text file for this example. Last “n” lines means, last 10 lines or 20 lines or 30 lines, etc. So “n” should be replaced by an appropriate non-zero positive integer value. Obviously the tail of the file is harder to do and this is really a much more challenging situation than getting the first n (10, 20, 30 etc.) lines. Because you are habituated to read the file…

Continue

Handling large data writing to Excel using SXSSF Apache POI

Introduction This tutorial will show you an example on handling large data writing to excel using sxssf Apache POI library. having said that we will see here how to write large data set to an Excel file using Apache POI using SXSSF. The theoretical text and concept have been borrowed from http://poi.apache.org/spreadsheet/how-to.html#sxssf SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows…

Continue

Append-String Transformer in Mule ESB

What is Mule ESB ? Mule ESB is a lightweight Java-based enterprise service bus (ESB) and integration platform that allows developers to connect applications together quickly and easily, enabling them to exchange data. Mule ESB enables easy integration of existing systems, regardless of the different technologies that the applications use, including JMS, Web Services, JDBC, HTTP, and more. This example shows how we can read a file from a source directory and append a string to the file content and display it into the console. We simply put a file…

Continue

File-To-String transformer in Mule ESB

What is Mule ESB ? Mule ESB is a lightweight Java-based enterprise service bus (ESB) and integration platform that allows developers to connect applications together quickly and easily, enabling them to exchange data. Mule ESB enables easy integration of existing systems, regardless of the different technologies that the applications use, including JMS, Web Services, JDBC, HTTP, and more. This example shows how we can read a file from a source directory and display the content into console. We simply put a file in a source directory and Mule will read…

Continue

Verify a string contains only numeric value in Java

Introduction The below example shows how to verify that a string contains only numeric value in Java. String may contain float value, double value etc. This example uses regular expression to check a string contains only numeric values. It makes sure that your string should contain only digits and dot(.). You may need sometimes to use string variable for storing numeric data. As the variable is string type, so by mistake your string variable may contain non-numeric values which are not correct values for processing further business logic. Therefore you…

Continue

String reverse example in Java

This tutorial will show you string reverse example in Java. We have various ways to reverse a string in Java and I have presented here five ways to reverse a string. String class in Java is an immutable class and that’s why it does not have reverse() method to reverse the given string. We will use here StringBuilder and StringBuffer‘s reverse() method, we will build our own custom method, using recursion with substring() method and Java 8’s Lambda and Stream API to reverse the given string.

Continue