Skip to content
Advertisement

Iterate Java Map but after skipping 1-st element

I have this Java Map:

JavaScript

I want to skip the first one:

JavaScript

But I get error: foreach not applicable to type 'java.util.stream.Stream<java.util.Map.Entry<java.lang.String,java.lang.String>>'

Do you know how I can fix this issue?

Advertisement

Answer

First use a LinkedHashMap if you want it ordered:

JavaScript

You are trying to iterate a stream which doesn’t work that way. Try this:

JavaScript

Alternatively you can convert your stream to a list. Now your driver variable doesn’t have to be “effectively final”.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement