How to convert a Java List to Map efficiently?

I see your point about the for-loop being reliable, but if you’re open to a more modern Java approach, I’d suggest using Java 8 Streams. I’ve found this approach much cleaner and more expressive for handling such conversions. Here’s how I would tackle the java list to map conversion:

Map<Integer, String> resultsMap = results.stream()
    .filter(o -> o.length >= 2 && o[0] instanceof Integer && o[1] instanceof String)
    .collect(Collectors.toMap(o -> (Integer) o[0], o -> (String) o[1]));

This is concise, functional, and a lot more readable in my opinion. It also has the benefit of clearly separating logic—no need for explicit loops. One thing to note: Collectors.toMap() will throw an exception if duplicate keys exist, which is great for avoiding silent errors, but if you expect duplicates, you can easily provide a merge function to handle them. It’s a perfect approach for those who prefer declarative programming when converting a java list to map.