Remove Vowel

Remove vowel in a string, vowel is 'aeiou'

It is straight forward

Method 1: str.replaceAll("[aeiouAEIOU]", "")

public static String removeVowels(String str) {
        if (str == null || str.length() == 0) return null;

        String ans = str.replaceAll("[aeiouAEIOU]","");

        return ans;
    }

Method 2: str.indexOf(ch) != -1

public String removeVowel(String str) {
  // test corner case
  if (str == null || str.length() == 0) {
      return null;
  }
  String vowel = "aeiouAEIOU";
  StringBuilder sb = new StringBuilder();

  for (int i = 0; i < str.length(); i++) {
      char ch = str.charAt(i);
      if (vowel.contains(ch)) continue;
      sb.append(ch);
  }
  return sb.toString();
}

results matching ""

    No results matching ""