Search Java Programs

Showing posts with label startsWith(). Show all posts
Showing posts with label startsWith(). Show all posts

Wednesday, January 20, 2010

Java String startsWith Example

String class startsWith method example.


String class startsWith method example:- This method demonstrates the working of startsWith method. this method returns boolean value on the basis of matching starting value and objects name with arguments.

Syntax:-startsWith(String prefix)

Here is the code:-

/**
* @(#) StartsWithString.java
* StartsWithString class demonstrates the working of startsWith() method of String class of lang package
* @version 16-May-2008
* @author Rose India Team
*/



public class StartsWithString {
public static void main(String args[]) {

String str = "he ram";
// method returns true if passed argument in quotes matches first the
// word of object value
boolean result = str.startsWith("he");
System.out.println("Method returns 'true': " + result);

// method returns true if passed argument not in quotes matches the
// object name
result = str.startsWith(str);
System.out.println("Method returns 'true': " +result);
}
}
Output of the program:-
Method returns 'true': true
Method returns 'true': true

Website Design by Mayuri Multimedia