1

I want to show threaded comments in java which is similar to any kind of website which has like facebook, Reddit etc. All my comments are storing in the SQL database. Which data structure is suitable for this? Is an open source library is there? Is there any SQL query or structure which returns the comments with its replies in a nested way? I am thinking of using tree data structure. If tree data structure is best than what is the efficient way of implementing this.

I want to get a message like this:-

comment
  reply
  reply
     reply
       reply
  reply
comment
  reply
  reply

Please give any suggestion.

Kartikeya Garg
  • 31
  • 1
  • 2
  • 4

1 Answers1

0

Because I'm familiar with SQL but not Java, my recommendation would be to store an indent number in the database.

When users click reply, take the indent number from the row above, and add one. Then in Java offset the reply by a factor of the indent number in your database.

LJ01
  • 589
  • 4
  • 11