0

for example, convert a String[][] {{"1","2"},{"3","4"},{"5","6"}} to a double[][] {{1.0,2.0},{3.0,4.0},{5.0,6.0}}. I tried:

Arrays.stream(strArr).map(s ->
            Arrays.stream(s).mapToDouble(Double::parseDouble).toArray()).toArray();

but it doesn't work.

1
  • 1
    What do you mean by "it doesn't work"? Is there an error message? Commented Aug 5, 2021 at 4:13

1 Answer 1

2

To create double[][], you need to use

double[][] result = Arrays.stream(input).map(s -> Arrays.stream(s).mapToDouble(Double::parseDouble).toArray()).toArray(double[][]::new);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.