App下載
首頁javastream_convertJava Stream - 如何轉(zhuǎn)換String流以加入它們

Java Stream - 如何轉(zhuǎn)換String流以加入它們

我們想知道如何轉(zhuǎn)換String流以加入它們。
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    // collect as typed array
    Stream<String> words = Stream.of("All", "men", "are", "created", "equal");
    final String joinedWords = words.collect(Collectors.joining(" "));
    System.out.println(joinedWords);

  }
}