Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Inserting In a List Date: Tue, 2 Apr 2013 22:52:20 +0000 (UTC) Organization: UK Free Software Network Lines: 25 Message-ID: References: NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1364943140 20725 84.45.235.129 (2 Apr 2013 22:52:20 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Tue, 2 Apr 2013 22:52:20 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.java.programmer:23198 On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote: > On 4/2/2013 5:06 PM, Martin Gregorie wrote: >>[...] >> Its also not clear to me whether the OP is expecting some form of >> sorted list of filenames. If he is expecting that, it would be best to >> use a TreeMap rather than an ArrayList to store the >> filenames. > > Is there a reason to prefer TreeMap (or other SortedMap) over > accumulate-disordered-and-sort-afterward? > I think so, yes, because none of File's list() and listFiles() methods guarantee the order of the returned files. By using TreeMap or equivalent the OP gets the sort for free, should it be required. I use it a lot, both for that and because accessing stored objects by key from a TreeMap is almost certainly faster than scanning an ArrayMap unless it contains very few objects indeed. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |