Java how to sort lowercase before uppercase strings

前端 未结 6 1003
南旧
南旧 2021-01-11 15:56

I want the files to be ordered by their abs path name, but I want the lowercase to be sorted before the uppercase. Example: Let\'s say I got 4 files:

files2.         


        
6条回答
  •  暖寄归人
    2021-01-11 16:08

    Collections.sort(); lets you pass a custom comparator for ordering. For case insensitive ordering String class provides a static final comparator called CASE_INSENSITIVE_ORDER.

    So in your case all that's needed is:

    Collections.sort(caps, String.CASE_INSENSITIVE_ORDER);

提交回复
热议问题