How to create a string from a Java Array?

Java 8Object Oriented ProgrammingProgramming

You can convert an array of Strings to a single array using the collect() method.

Example

Live Demo

import java.util.Arrays;
import java.util.stream.Collectors;

public class CreatngStringFromArray {
   public static void main(String args[]) {

      String [] myArray = {"Welcome", "to", "Tutorialspoint"};
      String str = Arrays.stream(myArray).collect(Collectors.joining(" "));
      System.out.println(str);
   }
}

Output

Welcome to Tutorialspoint
raja
Published on 10-Jan-2018 15:00:29
Advertisements