I want to iterate an object which has list inside list and so on. Since this data is huge in size, I want to exit all iterations when the if condition is met.
Since break is not supported in forEach, how can we achieve this? Is there any better solution other than using forEach to increase performance? Performance is key criteria here. Can I use streams / parallel streams here?
dataList.forEach(data -> data.getList()
.forEach(data1 -> data1.getList()
.forEach(data2 ->data2.getList()
.forEach(data3 ->data3.getList()
.forEach(data4 -> {
if (data4.getSomeData().equals(someData)) {
//some logic to populate some object using data1, data2, data3 & data4 fields
//I want to exit all the for each iterations if this condition is met. Since this list is very huge in size
}
})))));