Search code examples
javacharstring-parsing

What's the best way to check if a character is a vowel in Java?


I'm trying to check if a certain char is a vowel. What's the best way to go about doing this?


Solution

  • Here's the solution I've been using for a while, and it hasn't let me down yet:

    private static String VOWELS = "AÀÁÂÃÄÅĀĂĄǺȀȂẠẢẤẦẨẪẬẮẰẲẴẶḀÆǼEȄȆḔḖḘḚḜẸẺẼẾỀỂỄỆĒĔĖĘĚÈÉÊËIȈȊḬḮỈỊĨĪĬĮİÌÍÎÏIJOŒØǾȌȎṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢŌÒÓŎŐÔÕÖUŨŪŬŮŰŲÙÚÛÜȔȖṲṴṶṸṺỤỦỨỪỬỮỰYẙỲỴỶỸŶŸÝ";
    private static boolean isVowel(char c)
    {
        return VOWELS.indexOf(Character.toUpperCase(c)) >= 0;
    }
    

    For my applications, it's reasonably fast.