This is how my code looks :
public static String firstContainsChars(Stream<String> items,String charset) {
char[] inChars = charset.toCharArray();
for (char ch:inChars) {
items.filter(s->s.contains(String.valueOf(ch)));
}
return items.findFirst().orElse("No Match Found");
}
In fact, I am getting a collection of chars as a String
and filter
the stream but the problem is I can't use the stream several times in the foreach
loop and compiler says :
Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
Any ideas on how to duplicate the Stream without the need to collect it as a Collection
as it will be total waste. (streaming and collecting after the chnage)?