{"id":74,"date":"2008-05-27T12:39:21","date_gmt":"2008-05-27T16:39:21","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2008\/05\/27\/sort-an-array-of-file-objects-by-last-modified-date-in-java\/"},"modified":"2008-05-27T12:39:21","modified_gmt":"2008-05-27T16:39:21","slug":"sort-an-array-of-file-objects-by-last-modified-date-in-java","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2008\/05\/27\/sort-an-array-of-file-objects-by-last-modified-date-in-java\/","title":{"rendered":"Sort an array of File objects by last modified date in Java"},"content":{"rendered":"<pre class=\"code\">\n\/**\n * Sorts an array of Files by the last modified date property; if the second\n * parameter is \"desc\", then sorting is done descending order, otherwise\n * it will be ascending. \n * @param fList : An array of Java \"File\" objects, not sorted\n * @return File[] : An array of Java \"File\" objects, sorted by last modified date\n * @author C. Peter Chen http:\/\/dev-notes.com\n * @date 20080527\n *\/\npublic static File[] sortFilesByLastModDate(File[] fList, String order) {\n\tArrays.sort(fList, new Comparator<File>() {\n\t\tpublic int compare(File file1, File file2) {\n\t\t\tif (\"desc\".equals(\"order\")) {\n\t\t\t\treturn (int)(file2.lastModified() - file1.lastModified());\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (int)(file1.lastModified() - file2.lastModified());\n\t\t\t}\n\t\t}\n\t});\n\treturn fList;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a sample Java method that can be used to sort an array of Java&#8217;s File objects by the last modified date, either in ascending or descending order.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}