If you create a game, this data, hard-coded in your Java source code, will be painful. You will have to recompile every time you want to add a new element, change the relationship (which consists of what), etc.
Instead, I would recommend storing all the information about your element in an external source, and then reading it to / from it from your program. You can do this using a database, but I feel like I've gone too far (at least for now). Instead, you can use a readable, plain text, standardized format such as JSON to define your elements and their relationships from the outside, and then import all the data using the library (I suggest GSon ) for easy access to your program.
Regarding the data structure, I think your selection of HashMaps will work fine. Since JSON is built on two main types of list data structures [] and displays {} , that is what Gson converts anyway. Here is a very simple example of how I could present your item specification:
{ "elements" : { "iron" : "basic", "carbon" : "basic", "steel" : "intermediate" }, "formulae" : { "steel" : [ "iron", "carbon" ] } }
You can read this using Gson (or any other JSON library that you have selected) and then compile any other data structures that you need. If you can figure out how to get Gson to create the data structures you want directly (I know this is possible, but I donโt remember how difficult it is), then it will be even better. For example, if you can turn the value of the โformulaโ into a BidiMap ( Bidirectional Apache Commons map ), then this can be very useful (but you will also need to translate the list of components into a set so that it is non-specialized, for example, iron + carbon is something same as carbon + iron).
For more dynamic behavior, you can add a function to your program so that you can reload all the data of your elements during the game. (This may make debugging easier.)
I know that this is not quite what you asked, but I hope you find useful tips anyway!