Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to partial match with a string?

Tags:

java

How can I type partial letters of a word to find this word?

For example: I have a string array

 String[] s = {"Cartoon", "Cheese", "Truck", "Pizza"};

if I input partial letters, such as "ca","Che" or "piz"

then I can find the whole words for the list.

Thanks

like image 568
Crazymango Avatar asked May 22 '26 18:05

Crazymango


1 Answers

stringValue.contains("string that you wanna search");

.contains will do the job, iterate over the loop and keep adding the words in ArrayList<String> for the matched ones.

This could be a good read on string in java.

.contains is like '%word%' in mysql. There are other functions like .startsWith and .endsWith in java. You may use whatever suits the best.

like image 143
Danyal Sandeelo Avatar answered May 24 '26 17:05

Danyal Sandeelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!