Here is another way to do the same with threads in Java 8:
text.chars() .mapToObj(Character.UnicodeBlock::of) .filter(Character.UnicodeBlock.CYRILLIC::equals) .findAny() .ifPresent(character -> ));
Or in another way, keeping the index:
char[] textChars = text.toCharArray(); IntStream.range(0, textChars.length) .filter(index -> Character.UnicodeBlock.of(textChars[index]) .equals(Character.UnicodeBlock.CYRILLIC)) .findAny() // can use findFirst() .ifPresent(index -> );
Please note: I am using an array of characters here, not String, due to the performance advantage when retrieving an item by index.
source share