Sorting an array of String with custom ordering

后端 未结 4 1439
不知归路
不知归路 2020-11-30 10:27

I have a String array:

 String[] str = {\"ab\" , \"fog\", \"dog\", \"car\", \"bed\"};
 Arrays.sort(str);
 System.out.println(Arrays.toString(str         


        
4条回答
  •  离开以前
    2020-11-30 11:00

    Here you can find usefull link:

    Using comparator to make custom sort

    In your example instead comparing specific attributes of class you nedd to check possition of char in benchmarked String and base on this check if it's greather/equal/smaller.

提交回复
热议问题