---
title: "How to find string starts word in java?"  
description: "How to find string starts word in java?"  
author: "Anonymous User"  
published: 2014-10-17  
updated: 2014-10-17  
canonical: https://www.mindstick.com/forum/2401/how-to-find-string-starts-word-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to find string starts word in java?

Example: This is my string,\
String [sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) = "[random](https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c)";If the first [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) of the [string contains](https://www.mindstick.com/forum/159365/how-to-check-if-a-string-contains-letters-only-in-sql) 's' or 'p' or 'r' means i should [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) the character,Otherwise i have to return the original string.\
Is there any optimized way to do that like "[regex](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching)" or "StringUtils" in [apache](https://www.mindstick.com/blog/11351/mobile-application-development-using-apache-cordova) [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business)?

## Replies

### Reply by Anonymous User

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 }
```


---

Original Source: https://www.mindstick.com/forum/2401/how-to-find-string-starts-word-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
