I would recommend using an enumeration, as some suggested, although I would do it a little differently. Cards have a lot of overhead, and since your data is not dynamic, it is not very convenient. The atomic mass should be decimal (double or BigDecimal, depending on what you use it for), not int
public enum AtomicElement { HYDROGEN(1.00794), HELIUM(4.002602), ...; private double atomicMass; private AtomicElement (double atomicMass) { this.atomicMass = atomicMass; } public int getAtomicNumber() { return ordinal(); } public double getAtomicMass() { return atomicMass; } public static AtomicElement forAtomicNumber(int atomicNumber) { return AtomicElement.values()[atomicNumber]; } public static AtomicElement forElementName(String elementName) { return AtomicElement.valueOf(elementName); } }
Then you can search by atomic number or element name
AtomicElement.forAtomicNumber(2); AtomicElement.forElementName("CARBON");
This, however, assumes that you are going to represent the entire periodic table without spaces in the data, since it uses the value of ordinal () as an atomic number. If you need spaces, you will need to have an int field for the atomic number, and your function "forAtomicNumber" will have to cycle through "values ββ()" to find the number with the given number.
You can even expand this if you want to include known isotopes, etc., if your requirements dictate it.
source share