File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help improve this code without the use of HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help improve this code without the use of HashMap" Watch "help improve this code without the use of HashMap" New topic
Author

help improve this code without the use of HashMap

Paul Ngom
Ranch Hand

Joined: May 08, 2014
Posts: 312
    
    1
@Winston
I will check that out. Thanks for your availability.


I am always surprised at the added knowledge i can get from others when i give my opinion on a topic.
Paul Ngom
Ranch Hand

Joined: May 08, 2014
Posts: 312
    
    1
@Winston
Your hint led me to this:
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7894
    
  21

Paul Ngom wrote:Your hint led me to this:

OK, well Path has a toFile() method, and File has a toPath() method, so you can easily convert between the two. I think I've given you enough to get to your own solution. The important thing is to understand how that trawl() method works; don't just parrot the code. Otherwise, you'll be back as soon as you need to do something slightly different.

So, if you haven't already, get out a pencil and paper and write down what it does with a few sample file names. You don't need to be exhaustive, but do a few levels, so that you understand what's going on.
Unless you come from a pure maths background, recursion can be very difficult to "visualise". As I said previously, I've been at this lark a long time, and I still have to think hard about it.

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Paul Ngom
Ranch Hand

Joined: May 08, 2014
Posts: 312
    
    1
Now that i have two working programs, i will have to choose one. The code i posted first runs pretty faster if i remove the file i/o.
Anybody else who could share with us another way to achieve this. I mean listing all sub folders of a given directory no matter their level in the tree structure.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

You can always create a new File object from the current File's Canonical Path, then a new File object from the current File's Absolute Path, and then check if they are equal. Suspect NTFS is not gonna play nice with that though.


For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance. Depending on how lightweight your visitor is.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Paul Ngom
Ranch Hand

Joined: May 08, 2014
Posts: 312
    
    1

For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance.


Hi Dieter,
Could you please post a simple code about how this could be achieved? Thanks in advance.
 
GeeCON Prague 2014
 
subject: help improve this code without the use of HashMap