I want to sort string array based on on input string , for example thin we have these text
"united state"
"sample united"
"united kingdom"
"greece"
"uzbakestan"
so when user entered united , output will be :
"united state"
"united kingdom"
"sample united"
"greece"
"uzbakestan"
it shows united at first and sort them.
I am not sure I entirely understand what you are after – but if you want to print the strings that are “most similar” to your input string first:
You might want to create a
Comparator<String>that will compare between 2 strings according to their levenshtein distance from a 3rd string [your input String].Using this comparator – you can sort your array using
Arrays.sort(myArray,new MyCustomComparator(inputString)).If this is an
ArrayListlike the title suggest [conflicting title and question body] – you can useCollections.sort(myList,new MyCustomComparator(inputString))