0

I am new with Stream API in Java 8 and try to Collect String[][].

I want to split Fred:Corwill;Wilfred:Corwill; to [[Fred,Corwill],[Wilfred,Corwill]] but this code doesn't work.

public static String meeting(String s) {
    String[][] = Arrays.stream(s.split(";")).map(str -> 
    str.split(":")).collect(String[][]::new);
    return null;
}
Philip John
  • 5,275
  • 10
  • 43
  • 68

1 Answers1

2

Instead of collect use toArray:

String[][] array =
    Arrays.stream(s.split(";")).map(str -> str.split(":")).toArray(String[][]::new);
Andy Turner
  • 137,514
  • 11
  • 162
  • 243