Answer the question
In order to leave comments, you need to log in
How to get several from 2 objects via stream api?
there are two objects (obj1, obj2) of class A, each of them is a singly-directed list
i.e. contains a reference to the next object of class A, the last object refers to null
class A {
private A next; //ссылка на след объект
public A getNext() { //получить следующий объект
return this.next;
}
}
Stream.of( obj1, obj2 ). [ действие ] .collect(Collectors.toList())
Answer the question
In order to leave comments, you need to log in
Stream.of(obj1, obj2)
.flatMap(o -> Stream.generate(o::getNext)
.takeWhile(Objects::nonNull))
.collect(Collectors.toList())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question