list to string java
Convert List of Characters to String in Java
1. Using StringBuilder class
Simple solution would be to iterate through the list and create a new string with the help of StringBuilder class as shown below:
![]() |
| list to string java |
Looking to convert List to String Java? Lets have a look at how to convert a Java Collections List of elements to a String in Java.
2. Using join() method of joiner class :
Joiner class can be used to join pieces to text specified as an array, and return the results as a string.This method also called Guava method.
Joiner class can be used to join pieces to text specified as an array, and return the results as a string.This method also called Guava method.
3. Using List.toString(), String.substring() and String.replaceAll() method:
The toStrin() method on a list returns a string that is surrounded by square brackets and has commas between items. The idea is to get rid of square brackets using substring() method, and comma and space replace by using replaceAll() method.
The toStrin() method on a list returns a string that is surrounded by square brackets and has commas between items. The idea is to get rid of square brackets using substring() method, and comma and space replace by using replaceAll() method.
Implement the above method:
4. using Collectors:
In java 8 we can make use of stream API with collectors.
In java 8 we can make use of stream API with collectors.
Implement the above method:

Comments
Post a Comment