Skip to content
Advertisement

Converting string to Map in java 8

Can someone please guide me on how to achieve the below using Java 8. I don’t know how to get that counter as the key

JavaScript

Advertisement

Answer

You can use IntStream to get this thing done. Use the integer value as the key, and the relevant value in the string array at that index as the value of the map.

JavaScript

Another alternative that obviates the need of split would be,

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