Skip to content

Tag: java-8

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 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. Another

handle duplicate key in Collectors.toMap() function

I am creating a map which its (key,value) will be (name, address) in my Person object: In the duplicate key situation, I would like to skip to add the second address to the map and would like to log the name also. Skipping the duplicate address I can do already using mergeFunction, but in oder to log the name…

Java 8: How to convert String to Map?

I have a Map: I converted it to a String: How to convert utilMapString to Map in Java8? Who can help me with? Answer Split the string by , to get individual map entries. Then split them by = to get the key and the value. Note: As pointed out by Andreas@ in the comments, this is not a reliable

Void is not a functional interface

I am trying to subscribe observable like : It’s working fine but if I use method reference compiler gives error “void is not a functional iterface” Any one can explain little bit deep? As per me subscriber accept consumer functional interface, which doesn’t return anything but we can p…