Convert List of Characters to String in Java

JavaObject Oriented ProgrammingProgramming

Let’s say the following is our list of characters −

List<Character> list = Arrays.asList('W', 'e', 'l', 'c', 'o', 'm', 'e');

Convert the list of characters to string −

String string = list.stream().map(String::valueOf).collect(Collectors.joining());

Example

Following is the program to convert List of Characters to String in Java −

import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.List;
public class Demo {
   public static void main(String[] args) {
      List<Character> list = Arrays.asList('W', 'e', 'l', 'c', 'o', 'm', 'e');
      String string = list.stream().map(String::valueOf).collect(Collectors.joining());
      System.out.println("String = "+string);
   }
}

Output

String = Welcome
raja
Published on 25-Sep-2019 08:55:25
Advertisements