Pages

How to determine a word contain or not in a sentence using java ???

*******************************************************
COMPLETE SOURCE CODE FOR : DetermineStringContainSubstring.java
*******************************************************


public class DetermineStringContainSubstring
{
public static void main(String[]args)
{
String a="Welcome to java world";

String substring1="Welcome to java world";
String substring2="elc";
String substring3="Wel";
String substring4=" t";
String substring5="rld";

//CHECK MATCH WHOLE WORD
if(a.matches(substring1))
{
System.out.println("substring1 match to a");
}

//CHECK SUBSTRING NOT LOCATE AT START OR END OF STRING
if(a.indexOf(substring2)>0)
{
System.out.println("substring2 contain in a");
}

//CHECK SUBSTRING NOT LOCATE AT START OR END OF STRING
if(a.indexOf(substring4)>0)
{
System.out.println("substring4 contain in a");
}

//CHECK SUBSTRING LOCATE AT START OF STRING
if(a.startsWith(substring3))
{
System.out.println("substring3 contain in a");
}

//CHECK SUBSTRING LOCATE AT END OF STRING
if(a.endsWith(substring5))
{
System.out.println("substring5 contain in a");
}
}
}


*******************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You