I need to find the 1st free index on my file system with a stream of names as a source.
Consider the list: ["New2", "New4", "New0", "New1", ...] The 1st unused index of them will be 3.
int index = 0;
try (IntStream indexes = names.stream()
.filter(name -> name.startsWith("New"))
.mapToInt(Integer::parseInt)
.distinct()
.sorted())
{
// I was thinking about making possible indexes stream, removing existig ones from try-with-resource block, and getting .min().
IntStream.rangeClosed(0, 10)... // Idk what to do.
}
I ask someone to help me find the right syntax for my idea or suggest a better solution.
Ernio source
share