1
Map<String, List<String>> parameters;

Map<String, String[]> collect = parameters.entrySet().stream()
                .collect(Collectors.toMap(entry-> entry.getKey(),entry -> entry.getValue().toArray()));

I'm getting compiler error cannot resolve method 'getKey()'

0

2 Answers 2

3

You should create an array of the correct type (i.e. a String[] and not an Object[]):

Map<String, String[]> collect = 
    parameters.entrySet()
              .stream()
              .collect(Collectors.toMap(Map.Entry::getKey,
                                        entry -> entry.getValue().toArray(new String[0])));
Sign up to request clarification or add additional context in comments.

Comments

3

You have to use :

.toArray(String[]::new)

Instead of just :

.toArray()

because this one return Object[] not a String[]

As discussed in the comments my solution can be valid from Java11

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.