• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Joining two File[] arrays

 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make it i am losing my mind. Cant be done like this


file = oneArray + otherArray;
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic