Basically I'm just trying to find a way to find the closest match (not necessarily exact) of a String
For example, find "delicous"
in {"pie", "delicious", "test"}
This is pretty obvious, but the values in the array might not always be that distinct.
Could someone please help me with a way to achieve this.
Depends on how you define "closest" but one common way is by using a Levenshtein Distance score. Apache Commons has such a method in StringUtils.
From there your search method basically becomes: find the string in the collection which has the smallest Levenshtein distance for a given input.
There's nothing built into Java for that. You might try a third-party library like SecondString or FREJ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With