How to store hierarchical structure data in java?

nagesh

In database table, i have maintained parent and child folder relationship as shown below datatable. Using that relationship i need to create hierarchical structure in a jsp web page. To display that structure i used http://myfaces.apache.org/tomahawk t:tree2 component.My requirement is, I need to fetch data from database and store that relationship in java variable. To do that i need a recursive technique to store tree structure or(hierarchical structure) in java variable. Please help to find answer.

DataTable: enter image description here

hierarchical View of Directory structure: enter image description here

Thank you

Bitman

You can use recursion to iterate over it.

void processChilds(Item child) {
List<Item> childs = selectChilds(child);
    for(Item i: childs) {
       //do smth
       processChilds(i);
    }
}

Or you need to select all records at once and then parse it into your own structure of objects. It can be HashMap or your own tree-like structure.

class Item {
  List<Item> childs;
}

I suggest you go with the first one (because it's simple to code) unless your tree is really deep

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Which C# data structure is best/feasible to store hierarchical data

From Dev

How to show hierarchical data structure with RecycleView?

From Dev

How to show hierarchical data structure with RecycleView?

From Dev

How to store hierarchical data within Firebase

From Dev

Convert a POJO to Tree structure in Java 8 for representation of data in hierarchical structure

From Dev

How to define DDD Aggregate root for hierarchical data structure?

From Dev

In Clojure, How to read a hierarchical data structure from a text file?

From Dev

How do I store this hierarchical data using MySQL?

From Dev

Query hierarchical data structure in firebase

From Dev

Serialize a hierarchical structure of objects in java

From Dev

How to load a text file and store into data structure

From Dev

How to store a data structure on a hard drive

From Dev

How to index a hierarchical data?

From Dev

Obtaining mysql to get hierarchical data structure

From Dev

Sorting Closure Table Hierarchical Data Structure

From Dev

C# Data structure to store items in a hierarchical way that once a branch is built, it allows me to retrieve it and add it as part of another one

From Dev

Better way to store hierarchical data with known depth?

From Dev

Structure to store data

From Dev

How to aggregate a data.frame on both row and column names based on a hierarchical dictionary name structure?

From Dev

How to store data in an ArrayList in Java

From Dev

Using nested set model to store Hierarchical data in sqlite how can I move a category into another category

From Dev

How to find the root element in a hierarchical structure

From Dev

Data Structure required to store extracted POS tag text in Java

From Dev

Java: Efficient data structure to store object with no 'logical' duplicates

From Dev

How to search Hierarchical Data with Linq

From Dev

How to store data with a tree-like structure in Julia

From Dev

How can I store a data structure such as a Hashmap internally in Android?

From Dev

How to keep track, store and traverse a huge spherical data structure

From Dev

How to store a "complex" data structure in R (not "complex numbers")

Related Related

  1. 1

    Which C# data structure is best/feasible to store hierarchical data

  2. 2

    How to show hierarchical data structure with RecycleView?

  3. 3

    How to show hierarchical data structure with RecycleView?

  4. 4

    How to store hierarchical data within Firebase

  5. 5

    Convert a POJO to Tree structure in Java 8 for representation of data in hierarchical structure

  6. 6

    How to define DDD Aggregate root for hierarchical data structure?

  7. 7

    In Clojure, How to read a hierarchical data structure from a text file?

  8. 8

    How do I store this hierarchical data using MySQL?

  9. 9

    Query hierarchical data structure in firebase

  10. 10

    Serialize a hierarchical structure of objects in java

  11. 11

    How to load a text file and store into data structure

  12. 12

    How to store a data structure on a hard drive

  13. 13

    How to index a hierarchical data?

  14. 14

    Obtaining mysql to get hierarchical data structure

  15. 15

    Sorting Closure Table Hierarchical Data Structure

  16. 16

    C# Data structure to store items in a hierarchical way that once a branch is built, it allows me to retrieve it and add it as part of another one

  17. 17

    Better way to store hierarchical data with known depth?

  18. 18

    Structure to store data

  19. 19

    How to aggregate a data.frame on both row and column names based on a hierarchical dictionary name structure?

  20. 20

    How to store data in an ArrayList in Java

  21. 21

    Using nested set model to store Hierarchical data in sqlite how can I move a category into another category

  22. 22

    How to find the root element in a hierarchical structure

  23. 23

    Data Structure required to store extracted POS tag text in Java

  24. 24

    Java: Efficient data structure to store object with no 'logical' duplicates

  25. 25

    How to search Hierarchical Data with Linq

  26. 26

    How to store data with a tree-like structure in Julia

  27. 27

    How can I store a data structure such as a Hashmap internally in Android?

  28. 28

    How to keep track, store and traverse a huge spherical data structure

  29. 29

    How to store a "complex" data structure in R (not "complex numbers")

HotTag

Archive