Java #31: Two ways to check if a String contains another String in Java

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Two qays to check if a String contains another String

package dagbacomputers;

/**
*
* @author Akin
*/
public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//String that I will search for
String Name = “Alex”;

//String I will search within
String partyGuests = “The people coming are Sandra, Nick, Alex and Jennifer”;

//Printing test to check if partyGuests contains name
System.out.println(partyGuests.contains(Name));

//Test 2
System.out.println(“———-Test 2———–“);

//New String to Search For B
String notInvited = “Bobby”;

//Printing and Searching for a name that partyGuests does not contain
System.out.println(partyGuests.contains(notInvited));

//Second way to check for a string
System.out.println(“—-2nd way to test for a string——“);
//Searching for the word people
System.out.println(partyGuests.contains(“people”));

//Test 2
System.out.println(“———-Test 2————“);

//Searching for Harry Potter
System.out.println(partyGuests.contains(“Harry Potter”));
}//end of main

}//End of DagbaComputers Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: