I want to make simple parameter-value pairs of the form (SomeClass, SomeNumber) where the 1st thing is a parameter and second thing is its value. SomeNumber can be a whole number, fraction, negative number etc. SomeClass can be String, Color or anything that can be paired with "SomeNumber" .
ex of employee and salaries. (John, 19.75), (David, 25.50), (Cathy, 102.50) ex for color codes (Color.black, 0), (Color.blue, 2) etc.
Is it a good idea? If not why? If yes, then how do I do it in Java?
What you are talking about is Map
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Try HashMap
Map<String,Double> myMap = new HashMap<String,Double>();
| |
| |
SomeClass SomeNumber
myMap.put("John", 19.75);
SomeNumber num = myMap.get("John");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With