My list consist of list character definition like List<Character> listCharacter = new ArrayList<Character>();
Character class:
private List<Result> results;
Result Class :
private int id;
private String name;
I am trying to iterate over listCharacter like
listCharacter.forEach((characters) -> {
characters.getResults().forEach((result) -> {
if (result.getId() == id) {
return result;
}
});
});
But when am trying this i got foreach not applicable the type Iterable is not applicable for the arguments (( result) -> {}) error . I know chain loop not possible with foreach loop.
Also i know we can use consumers like duplicate question solutions.But then i can't reach outer loop variable inside inner loop.The Consumer classes just using it and disposing it.Therefore I don't wanna use that.
How can i do this i mean reaching outer loop variable inside inner loop without dealing with this such errors?
TLDR: I have 2 list objects. I am iterating over outer one(listCharacter) that who has inner one list object(result) which has id and name.If the id matched the method would return.That's all.
forEachdoesn't return. I think you want tomappossibly you want toflatMap.Characteras that already exists in the Java API. consider changing it to something more meaningful. currentlyprivate Result results;is not iterable . is that suppose to be aList<Result> resultsinstead withinCharacterclass?.idunique across all characters? (If so, there is a much simpler approach!)