• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Joining two File[] arrays

 
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to make it i am losing my mind. Cant be done like this


file = oneArray + otherArray;
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic