Q:

Java program to demonstrate example of String.startsWith() and String.endsWith()?

belongs to collection: Java String Programs

0

1) boolean String.startsWith(String prefix)

This function returns "true" if staring starts with "prefix" (substring) otherwise it returns "false".

2) boolean String.endsWith(String postfix)

This function returns "true" if staring ends with "prefix" (substring) otherwise it returns "false".

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Example of String.startsWith()

public class JavaStringStartsWithPrg{
	public static void main(String args[])
	{
		String str="www.includehelp.com";

		if(str.startsWith("www")==true)
			System.out.println("String starts with www");
		else
			System.out.println("String does not start with www");
	}
}

Output

String starts with www

Example of String.endsWith()

public class JavaStringEndsWithPrg{
	public static void main(String args[])
	{
		String str="www.includehelp.com";

		if(str.endsWith(".com")==true)
			System.out.println("String ends with .com");
		else
			System.out.println("String does not end with .com");
	}
}

Output

String ends with .com

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to replace string with another string in java ... >>
<< How to spilt string in substrings using String.spl...