Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write a Java program to Replace Vowel letter with Capital the given String . Example -" Engineer"

Write a Java program ( Java 8 version ) to Replace Vowel letter with Capital the given String . Example – "Engineer".
The output is – EngInEEr.

Write a Java program ( Java 8 version ) to Replace Vowel letter with Capital the given String . Example – "Engineer".
I could not able to find the solution.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the String#chars method to stream the characters, and utilize the IntStream#mapToObject method to map the values to String values.

You’ll have to cast letter to a char each time though, since the chars method uses an IntStream.

String string = "Engineer";
string = string.chars().mapToObj(letter -> {
    switch ((char) letter) {
        case 'a', 'e', 'i', 'o', 'u' -> {
            return String.valueOf((char) letter).toUpperCase();
        }
        default -> {
            return String.valueOf((char) letter);
        }
    }
}).collect(Collectors.joining());

Output

EngInEEr
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading