Java equivalent of C++ +’s “std::string::find_first_of”

Java equivalent of C++ +’s “std::string::find_first_of” … here is a solution to the problem.

Java equivalent of C++ +’s “std::string::find_first_of”

Is there any Java equivalent for “std::string::find_first_of” in C++?

 string string1( "This is a test string!");
 int location = string1.find_first_of( "aeiou" );
 location is now "2" (the position of "i")

What is the easiest way to achieve the same functionality?

Edit: The proposed solution must also work for Android.

Solution

Do not use external libraries:

     String string = "This is a test string!";
     String letters = "aeiou";
     Pattern pattern = Pattern.compile("[" + letters + "]");
     Matcher matcher = pattern.matcher(string);
     int position = -1;
     if (matcher.find()) {
         position = matcher.start();
     }
     System.out.println(position);  prints 2

Related Problems and Solutions