For completeness (although several good answers have been provided, I like Mark's and Joachim's best), here are two versions based on String.split(regex) and String.split(regex, limit):
(Edit, bug fix:)
boolean containsAtLeastTwoAsterisks = ("_" + myString + "_").split("\\*", 3).length == 3;
boolean containsExactlyTwoAsterisks = ("_" + myString + "_").split("\\*").length == 3;
I wrote a little benchmark based on our answers (I know, benchmarks don't mean much, but they are fun, and mine is probably crap, I know.) Anyway, here are the results for a sample run:
*********************************************************************************
Testing strings with one or less asterisk
Processor: bhups
Finished. Duration: 40 ms, errors: 0
Processor: Bozho (loop version)
Finished. Duration: 33 ms, errors: 0
Processor: Bozho (regex version)
Finished. Duration: 806 ms, errors: 0
Processor: Joachim Sauer
Finished. Duration: 24 ms, errors: 0 <-- winner
Processor: Mark Byers
Finished. Duration: 1068 ms, errors: 0
Processor: seanizer
Finished. Duration: 408 ms, errors: 0
*********************************************************************************
Testing strings with exactly two asterisks
Processor: bhups
Finished. Duration: 14 ms, errors: 0 <-- winner
Processor: Bozho (loop version)
Finished. Duration: 21 ms, errors: 0
Processor: Bozho (regex version)
Finished. Duration: 693 ms, errors: 0
Processor: Joachim Sauer
Finished. Duration: 14 ms, errors: 0 <-- winner
Processor: Mark Byers
Finished. Duration: 491 ms, errors: 0
Processor: seanizer
Finished. Duration: 340 ms, errors: 0
*********************************************************************************
Testing strings with more than two asterisks (not all processors will be included)
Skipping processor bhups
Processor: Bozho (loop version)
Finished. Duration: 63 ms, errors: 0 <-- winner
Skipping processor Bozho (regex version)
Skipping processor Joachim Sauer
Processor: Mark Byers
Finished. Duration: 1555 ms, errors: 0
Processor: seanizer
Finished. Duration: 860 ms, errors: 0
Seems like non-regex is a lot faster than regex. That's what you'ld expect, I guess.
EDIT: fixed wrong winner. sorry, joachim