dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 24, 2020

See if a String Contains Given Words in Java

We can use the AnyMatch method to figure out if a string contains any of the given words from an Array. See below for a sample:

List middleEasternCountries = Arrays.asList("egypt", "iran", "turkey");
String sampleString = "Egypt is a famous tourist destination. It contains the Pyramids";

System.out.println(middleEasternCountries.stream().anyMatch(sampleString::contains));
Srinath M S
 
Thanks for your registration, follow us on our social networks to keep up-to-date