How to use Collections or Sets to organize data structures inside data structures in Java?

By | October 30, 2018
Questions:

I have several lists of entity names which compose a dataset that is organized, for example:

  • ENT_01
  • ENT_02
  • ENT_nn

Being any number of lists of different entity names (as Strings) always numbered from 01 to nn.

What I intend to do is read them, and create some data structure that utilizes the entity root name (ex. ENT) and associate each instance of it (ex. ENT_01, ENT_02) to itself. Meaning that when I call ENT I could use it (or its position in a List, ArrayList, etc) as a parameter to retriveve de whole numbered structure. Problem being, I also need a way to easily access each numbered entity instances.

I thought about and tried based on this question to implement an “ArrayList of ArrayLists”, with the first being the rootname and the second containing the instances, but it looked inefficient and improvised way to do it.

Is there any structure or class, maybe under Collections and/or Sets, in Java which would do it in a more elegant and effcient way?

Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *