use a Or An - Java java.lang

Java examples for java.lang:String Algorithm

Description

use a Or An

Demo Code


//package com.java2s;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        String str = "java2s.com";
        System.out.println(aOrAn(str));
    }//w w w.j a  v  a  2 s .c om

    private static List<Character> vowels = new ArrayList<Character>() {
        {
            add('a');
            add('e');
            add('i');
            add('o');
            add('u');
        }
    };

    public static String aOrAn(String str) {
        if (vowels.contains(str.charAt(0))) {
            return "an " + str;
        } // if

        return "a " + str;
    }
}

Related Tutorials