I have a list of DTO received from a DB, and they have an ID. I want to ensure that my list contains an object with a specified ID. Apparently creating an object with expect
This is what I used in my DFS GetUnvisitedNeighbour function.
public static int GetUnvisitedNeighbour(int v)
{
Vertex vertex = VertexList.stream().filter(c -> c.Data == v).findFirst().get();
int position = VertexList.indexOf(vertex);
...
}
I used to work in C#. Lambda expressions in C# are much easier to work with than they are in Java.
You can use filter function to add condition for property of element.
Then use findFirst().get() or findAny.get() according to your logic.