How to eliminate Vowels from a string in java? -


i want eliminate vowels string, can eliminate them, fail return them main(). got exact output using following code.

string string = "ajeiokluj";     string s = string.replaceall("[aeiouaeiou]","");    return s;    

it great if required output came using loop.

hope have written code similar below considering fail return statement .

public static void main(string[] args) {         string string = "ajeiokluj";             string s = eliminatevowels(string);            system.out.println(s);      }      private static string eliminatevowels(string string) {         string s = string.replaceall("[aeiouaeiou]","");         return s;     } 

if did works fine , if not use above reference ;)

based on comments since looking using for loop (which not recommended) please find code below.

public static string removevowels(final string string){         final string vowels = "aaeeiioouu";         final stringbuilder builder = new stringbuilder();         for(final char c : string.tochararray())             if(vowels.indexof(c) < 0)                 builder.append(c);         return builder.tostring();     } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -