Download an Excel using Servlet

How to download an Excel using Servlet? Create a workbook using any frameworks and write out the created workbook to response.getoutputstream(). For creating the excelsheet I am using apache poi. Set the content type of response to “application/vnd.ms-excel” and set response header as   “Content-Disposition”, “attachment; filename=YourExcelName.xls”. Download an Excel using Servlet Example   Discussion Should I close HttpServletResponse.getOutputStream()? You … Read more

Flatten a list of Strings

In this tutorial we would see at various ways to concatenate a list of strings and insert a separator “,”  in between the concatenated strings. Java 8 output Using org.apache.commons.lang3.StringUtils output : Using loop See concatenation comparison for choosing a better way for string concatenation. output

Runtime comparison of string concatenation

One of the mostly asked questions is “How should I do string concatenation?”. And the answer to this question is not very straight forward.  Here I would benchmark the three string concatenation operations. Tools Used I am using jmh to do the benchmarking. And used maven to run the benchmark code  on java 8 as recommended … Read more

Convert List to Array in Java

In this tutorial we will see how to convert a list of objects to an Array.  That can be done by toArray method on the list. We are going to use the below two methods to do the conversion. Both these methods preserve order of the original list being converted. We would also discuss the conversion of … Read more