Example of contains(charSequence s) method of String class in java.


Posted in : Core Java Posted on : November 11, 2010 at 5:55 PM Comments : [ 0 ]
Advertisements
Example of contains(charSequence s) method of String class in java.

Example of contains(charSequence s) method of String class in java.

In this java example, we will explain about the contains(charSequence s) method of String class in java. The contains(..) method alwayd returns boolean value. It returns true if specified character sequence is present in this string, otherwise returns false.

Code:
ContainsMethod.java
public class ContainsMethod {
public static void main(String[] args) {
	String string = "Bharat Singh Gangwar";
	System.out.println("Given string : " + string);
	CharSequence searchStr = "Singh";
	CharSequence searchStr1 = "Kumar";
	if (string.contains(searchStr)) {
	   System.out.println("String contains sub string : " + searchStr);
	} else {
	  System.out.println("String does not contains sub string : "
			+ searchStr);
	        }
	if (string.contains(searchStr1)) {
	System.out.println("String contains sub string : " + searchStr1);
	} else {
	System.out.println("String does not contains sub string : "
		+ searchStr1);
        }
    }
} 
Output:
Element of character array.
B h a r a t
String of character value : Bharat

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Tutorial Topics