I just realized that implementing the following algorithm to compute the hash code for a stream is not possible using Stream.reduce(...). The problem is that the initial see
Holger wrote the right solution, if you want a simple way of doing it there are two additional possibilities:
List and call hashCode()Stream extends Object> stream;
int hashCode = stream.collect(toList()).hashCode();
Stream.iterator()Stream extends Object> stream;
Iterator extends Object> iter = stream.iterator();
int hashCode = 1;
while(iter.hasNext()) {
hashCode = 31 *hashCode + Objects.hashCode(iter.next());
}
Just as a reminder the algorithm that List.hashCode() uses:
int hashCode = 1;
for (E e : list)
hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());