• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Sorting Array of files by descending date and time format

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ahve list of txt filesin 'n directory
rolebased071607001038042.txt
crf-crf072307001037051.txt
crfonlyd073107001037060.txt

The above filenames contain the following (taking the first file as an example):
rolebased - This is the rolebasedinformation
071607 - This is the date (mmddyy)
001038042- This is the time including milliseconds(00:10:38:042 AM)


I need to sort these files descendingly according to date and then time (process the oldest files first, and the newest files last).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several sorting implementations in the Java library that know everything but how to compare two items. You can provide the comparison logic in a Comparable method on the objects, or in a separate Comparator object. If you're working with String or File objects, you want to make a Comparator.

See Arrays.sort() or TreeSet(comparator). Try to write something using one of these - it should only be a few lines long - and show us what you make!
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic