0

I am struggling to have a proper implementation in java when it is required to have a set of constants values in String and those strings have the values again in integer/String. for example,

  1. small-diesel-car : 142g
  2. small-petrol-car : 154g
  3. small-plugin-hybrid-car : 73g
  4. small-electric-car : 50g

So, I have defined those Strings literals in Constants.java like:

public static final String SMALL_DIESEL_CAR = "small-diesel-car";

But now "small-diesel-car" should have a value of 142.

My question is: How should I be handling this scenario using constants and enum classes or anything else?

halfer
  • 19,824
  • 17
  • 99
  • 186
Bilva
  • 1
  • Duplicate of: https://stackoverflow.com/questions/4197988/java-enum-valueof-with-multiple-values You can ref to this answer: https://stackoverflow.com/a/4198066/2384806 – mdoflaz Jun 29 '22 at 08:59
  • Yes, It does answer. Thank you! – Bilva Jun 29 '22 at 09:04

0 Answers0