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.