Java sort String array of file names by their extension

前端 未结 8 769
后悔当初
后悔当初 2021-01-13 02:29

I have an array of filenames and need to sort that array by the extensions of the filename. Is there an easy way to do this?

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 02:45

    Create a Comparator and compare the string extensions. Take a look at the following

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html

    Then pass in your List of strings to Arrays.sort(List, Comparator)

提交回复
热议问题