0

So, basically, I'm trying to organize paths into an array (list or map) to replicate that directory structure of said paths.

So, for example:

res/icons/java.png
src/Main.java
src/somepackage/Stuff.java
lib/somelib.jar

And the idea is to store them into a data structure that's possible to iterate into some form of GUI display. Like a TreeView (JavaFX).

I was thinking of doing it by putting all of the paths into a regular String[] arrray and then looping through them and splitting each one by "/" and then checking if each part that is a folder already exists in a data structure. If it does, then just place the file at the end into it and then if not, then create an array where key = folder name and values = files.

tl;dr - is there a java array like structure that can be used to replicate a directory like structure?

2
  • javax.swing.tree: TreeModel, DefaultTreeModel. MEant to coop with JTree. Very simple. See demos in some tutorial.
    – laune
    Feb 14, 2015 at 15:04
  • @laune - Will a defaulttreemodel be suitable even if it's not for a Swing jtree? I'll try it out, thanks for the suggestion. Feb 14, 2015 at 15:05

1 Answer 1

0

Consider a recursive approach. In pseudocode:

Class Item
    Boolean isFile
    String title
    List<Item> items

    AddItem(item)
    RemoveItem(item)
    Iterate()

In this class, you can extend ArrayList<Item>. In that case you don't need to hold the list of items. You would also have lots of method to use directly. If you need help to put in Java please say so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.