Cherry :
With Collection
everything is clear, but what about the following:
There is an object
with a count()
method and a getPart(int i)
method. So extracting all objects leads to the following boilerplate code:
List<Part> result = new ArrayList<Part>();
for (int i = 0, i < object.count(), i++) {
result.add(object.getPart(i));
}
return result.stream();
Is there any standard way to pass just 2 producers: () -> object.count()
and (int i) -> object.getPart(i)
to create a stream? Like this:
SomeUtil.stream(object::count, object::getPart);
MBec :
Try this:
IntStream.range(0, object.count()).mapToObj(object::getPart);
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=446520&siteId=1