Home > DeveloperSection > Forums > How to find string starts word in java?
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    October-17-2014 12:41 AM

 Java Java 
Ratings:


 1 Reply(s)
 600  View(s)
Rate this:
Example: This is my string,

String sample = "random";
If the first character of the string contains 's' or 'p' or 'r' means i should remove the character,Otherwise i have to return the original string.

Is there any optimized way to do that like "regex" or "StringUtils" in apache common?


ben reitman
ben reitman

Total Post:96

Points:676
Posted on    October-17-2014 12:43 AM

Why do you want to add 3rd party jar for this kind of simple requirement? You can try as follows

String sample = "random";
if(sample.startsWith("s")||sample.startsWith("r")||sample.startsWith("p")){
  // do necessary 
}else{
  // do necessary 
}

Don't want to miss updates? Please click the below button!

Follow MindStick