-1

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
  • 4,776
  • 9
  • 39
  • 64

1 Answers1

1

Instead of collect use toArray:

String[][] array =
    Arrays.stream(s.split(";")).map(str -> str.split(":")).toArray(String[][]::new);
Andy Turner
  • 131,952
  • 11
  • 151
  • 228