How to display flat data structure into hierarchical data structure (Java)?

前端 未结 5 1687
我在风中等你
我在风中等你 2021-02-02 15:11

I have recently faced this question in a practical test for a job .

Suppose you are given a flat data structure like this :

**Category**         **Name**         


        
5条回答
  •  梦谈多话
    2021-02-02 15:20

    You could have a design inspired by Swing TreeModel.

    EDIT When I say that, I mean you could use a class implementing a likewise interface; Noticeyou can even go as far as using directly this interface, as Swing is a part of standard JRE and is available everywhere standard Java is avaiable.

    Furthermore, as it is an interface (and not a class), it's only a way for you to structure your calls. As a consequence, you can easily use it in a console based application.

提交回复
热议问题