This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Joining two File[] arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Joining two File[] arrays" Watch "Joining two File[] arrays" New topic
Author

Joining two File[] arrays

mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

How to make it i am losing my mind. Cant be done like this


file = oneArray + otherArray;
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1409

What exactly are you trying to accomplish?
If you simply want to merge two arrays, not caring about duplicates, I think making use of System.arraycopy() will probably yield the best performance.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

k the actual problem is making FileSystemTableModel so it would display the system in table. The file list i get with File class. And two arrays are because i want the folders listed first and files after folders.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

There is another way of solving this: just list them all (listFiles), then use Arrays.sort to sort them. You will need a Comparator for that:

This will also help you with the sorting of your files. You cannot assume that listFiles will return your files in alphabetical order; some operating systems use creation date sorting.

Of course this method is O(n log n) against the O(n) of listing the files twice, then merging, but unless there are a lot of files / folders in each folder you won't notice the difference.


By the way, that code came out of my own FileTreeModel, so it has proven itself already in existing code
[ June 11, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Joining two File[] arrays
 
Similar Threads
Creating a file by giving relative path
WA #1.....word association
java io
Struts FormFile (parsing .csv files)
performance issues with file read and write