unexpected String.join() behavior

I tried to print contents of a List<String> with a "," in between them. Followed the book Functional Programming in Java by Venkat Subramaniam, on page 54 , he did exactly what I am doing but my print result is coming as a single string without a comma(,).

String[][] deepArrayStr = new String[][]{{"Alex", "nullpointer"}, {"Eran", "George"}};
 List<String> str= Arrays.stream(deepArrayStr)
     .flatMap(Arrays::stream)
     .collect(Collectors.toList());
for(String s:str){
    System.out.print(String.join(",",s));
}

OutputAlexnullpointerEranGeorge

ExpectedAlex,nullpointer,Eran,George

I tried another way and it works fine, I just wanted to know is there anything that I am doing wrong in the above approach whereas in the book Venkat also did the same thing that I am doing?

 System.out.println(Arrays.stream(deepArrayStr)
        .flatMap(Arrays::stream)
        .collect(Collectors.joining(",")));

OutputAlex,nullpointer,Eran,George

ExpectedAlex,nullpointer,Eran,George

My question is not to convert from List to string but to add delimiter while printing.

#java

1 Likes1.50 GEEK