string.contains()
String.contains() search for matching sequnce of string
Syntax
String1.contains(String2)
The output is boolean ( true or false )
Here are some examples with output.
String my_str1="Welcome to plus2net";
System.out.println(my_str1.contains("2")); // true
System.out.println(my_str1.contains("net")); // true
System.out.println(my_str1.contains("plus2net")); // true
System.out.println(my_str1.contains("co")); // true
System.out.println(my_str1.contains("no")); // false
Searching for @ and . inside email address.
String my_str1="userid@example.com";
System.out.println(my_str1.contains("@")); // true
System.out.println(my_str1.contains(".")); // true
System.out.println(my_str1.contains(" ")); // false
« All String functions
« Java
This article is written by plus2net.com team.
plus2net.com