Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't iterate through HttpHeaders Map

Tags:

java

loops

My IDE says

Error: can only iterate over an array or an instance of java.lang.Iterable

On the headers.map() in this code

import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;

public static String dumpRequest(HttpRequest request)
{
    HttpHeaders headers = request.headers();
    for (Map.Entry<String, List<String>> header : headers.map()) {

    }
}

However the documentation of the map() in my IDE says it returns a Map<String, List<String>> , what am I missing ? please consider I'm very new to JAVA

I'm using JAVA 14

This is the documentation of HttpHeaders that I'm using

like image 531
Accountant م Avatar asked Feb 14 '26 16:02

Accountant م


1 Answers

Close.

for (Map.Entry<String, List<String>> header : headers.map().entrySet())

Map itself does not extend the Iterable interface, so it can't be iterated using foreach.

like image 176
Sean Patrick Floyd Avatar answered Feb 16 '26 05:02

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!