I have a text file like this:
ids.txt
1000
999
745
123
...
I want to read this file and load it in a two dimension
Given a Stream
you can parse each item to an int
and wrap it into an Object[]
using:
strings
.filter(s -> s.trim().length() > 0)
.map(Integer::parseInt)
.map(i -> new Object[]{i})
Now to turn that result into a Object[][]
you can simply do:
Object[][] result = strings
.filter(s -> s.trim().length() > 0)
.map(Integer::parseInt)
.map(i -> new Object[]{i})
.toArray(Object[][]::new);
For the input:
final Stream strings = Stream.of("1000", "999", "745", "123");
Output:
[[1000], [999], [745], [123]]