Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Optional;
- public class Acronym {
- public static String generate(String source) {
- String[] words = source.split("\\b");
- for (String word : words) {
- System.out.println(word);
- }
- Optional<String> acronym = Arrays.stream(words)
- .filter(word -> word.matches("^[a-zA-Z]+$"))
- .reduce((String var0, String var1) -> var0 + var1.substring(0, 1).toUpperCase());
- if (!acronym.isPresent()) {
- throw new RuntimeException();
- }
- return acronym.get();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement