Basically what I want to do is to write a for loop like below with java 8 features,
private String createHashCode() {
for (int i = 0; i < MAX_TRY; i++) {
final String hashCode = createRandomString();
if (!ishashCodeExistence(hashCode)) {
return hashCode;
}
}
throw new HashCodeCollisonException();
}
what I tried is ;
private String createHashCode() {
IntStream.range(0, MAX_TRY).forEach($ -> {
final String hashCode = createRandomString();
if (!ishashCodeExistence(hashCode)) {
return hashCode;
}
});
throw new HashCodeCollisonException();
}
However, foreach method in lambda returns void so that I cannot return a string.
Is there any way to write my method instead of using normal for loop?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…