Java String Handling

Convert String array to String in Java example

Convert String array to String in Java example shows how to convert String array to String in Java. Example also shows how to convert String array to String using various approaches.

How to convert String array to String in Java?

There are several ways using which you can convert String array to String as given below.

1) Convert String array to String using for loop and StringBuilder

You can use for each loop to iterate over an array and append each element of an array to StringBuilder. Finally, you can convert StringBuilder to String using toString method as given below.

Output

Note: If you are using Java 1.4 or earlier version, use StringBuffer instead of StringBuilder class.

2) Convert String array to String using Arrays class

You can convert String array to List and then use toString method of Arrays class to convert it to the string as given below.

Output

If you want to remove square brackets from the string, use following regular expression to replace them with the empty string.

3) Convert String array to String using Apache Commons library

If you are using Apache Commons library, you can use join method of StringUtils class to join array elements as given below.

Output

4) Convert String array to String using join method of String class (Java 8)

If you are using Java 8, you can use join method of String class to join array elements and create String as given below.

Output

5) Convert String array to String using toString method of Arrays class

You can use toString method of Arrays class to convert array to String object as given below.

Output

Please let us know your views in the comments section below.

 

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.

About the author

rahimv

rahimv

rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *