I need to sort an array in which the corresponding elements appear, and others down.
For example. I have an array: [z, asxdf, abasdf, abcasdf, b, bc, bcd, c] I need it when I pass KeyWord, suppose "b" , then it should sort the given array, in which the first line starts with b. . , and rest after that. Which will generate the final result: [b, bc, bcd, z, c, .. (rest).]
If possible using a comparator in Java?
String keyWord = "b"; String[] s = {"z", "asxdf", "abasdf", "abcasdf", "b", "bc", "bcd", "c"}; Arrays.sort(s, new Comparator<String>() { @Override public int compare(String o1, String o2) {
Result -> [ b , bc , bcd , z , c , ...]
(I can use List instead of Array or whatever if it helps me solve this problem)