Tree-like data structure?

F

fishfry

Using the File class I'm able to recursively traverse my local
filesystem. I'm wondering how do Java programmers store this type of
info, ie is there a Tree collection of some kind? I've seen JTree and it
would make sense for there to be a corresponding data structure you can
just attach to the Jtree.
 
C

Chris R.

In the javax.swing heirarchy you'll find an interface called TreeModel
and a class that implements it called DefaultTreeModel. Good odds that
those will suit you.
 
T

Tony Morris

fishfry said:
Using the File class I'm able to recursively traverse my local
filesystem. I'm wondering how do Java programmers store this type of
info, ie is there a Tree collection of some kind? I've seen JTree and it
would make sense for there to be a corresponding data structure you can
just attach to the Jtree.

A file system closely resembles a B-Tree data structure.
Files represent leaves, and directories represent all other nodes that
aren't leaves.

The core API does not contain any such data structure, but it would be very
trivial to implement your own.

class BTreeNode
{
private Object data;
private List<BTreeNode> children;

// etc.
}

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
S

S Manohar

I have used DefaultMutableTreeNode, from the javax.swing.tree package;
There are a few convenient methods to trace back + forward through
trees. But sometimes it's more efficient to write your own (simpler)
data unit.
 
N

nos

Tony Morris said:
A file system closely resembles a B-Tree data structure.
Files represent leaves, and directories represent all other nodes that
aren't leaves.


The windows NTFS file system is implemented as a b-tree.

The core API does not contain any such data structure, but it would be very
trivial to implement your own.

class BTreeNode
{
private Object data;
private List<BTreeNode> children;

// etc.
}

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top