How to join strings in Java using the Apache Commons StringUtils class



This example shows how to join values together into a String using the Apache Commons Lang library. The StringUtils class comes with many overloaded versions of the join() method and the example below shows a few of them.

The first join call is made by passing in a list of Integers and a dash-separator to the join method.

The second and third call is made by passing in an iterator and a separator. First by sending in an iterator from the keyset of a map, and the second by passing in an iterator from the values of the same map.

The last call is made by passing in an array of Objects and a null separator. The null seperator will just join the values together without anything in between.

The output from the code above looks like this:







Search for more Java info on this site here:
Custom Search


Please type any questions here.