Skip to content
Advertisement

Tag: java-stream

Merging multiple lists to one list of Objects in stream?

I have code like this. It uses JSoap library. I am getting titles, magnets, seeds, leechers (these two together as TorrentStats) from torrent site. Now I want to merge them inside one List, of course it’s pretty easy to do it in standard for loop but is there any way to map or flatmap them in stream? Answer You can

Ignore exception in stream operations

Assuming you have an exception (checked/unchecked) in a stream operation and you want to ignore from now on this element. The stream must not be aborted, just ignoring elements throwing exceptions. I explicitly avoid saying skip, because it is a stream operation. So the example is using the map() operation for demonstration. Here I have a division by zero (for

How can I create a stream of objects?

Let’s say I have: and Then in a service, I have: It is not allowed to do the following: But ultimately, I have other classes that would share this interface and would want to do: Is there a way around this? Like using flatMap? (I noticed that if I have a wrapper class on a List of SomeClass objects, I

How To Store Values in Hashmap (comma Separated) with Same Key using Java Stream API?

I have a object named EntityObjectDTO like below: This AttributeType is an enum and can have values (RAW,REFERRED,ORIGINAL). I am trying to store all the attributes names and dataType into Hashmap of String key and value. This DataType can be duplicate as well. Input: Expected in a HashMap: {“Vehicle”,”name1,name2″} {“Person”,”name3″} This is what I tried: But by this I am

Advertisement