Contains Method In Java Explored And Experimented (String Functions In Java)
There are various inbuild string handling methods in java.
In this post we will discuss about the .contains() method in java.
.contains() method will check whether a sequence of characters is in the given string.
This Method is Case sensitive.
public class ContainsMethod
{
public static void main(String[] args)
{
String s1="lets learn programming";
String s2="lets learn programmingg";
//1. contains() -> check whether string contains the given sequence of characters
System.out.println(s1.contains("Programming")); // it return false because Programming and programming are not same i.e case sensitive
System.out.println(s1.contains("programming")); // it return true because programming and programming are same
System.out.println(s1.contains("gram")); // it return true because there is gram in programming
System.out.println(s1.contains("ts learn")); // it return true because lets learn programming has ts learn in sequence