When working with Javascript, we have the ability to create statements like the one below.
var f_names = {
'a' : 'Apple',
'b' : 'Banana'
'c' : 'Carrot'
};
This allows us to retrieve a specific value by calling f_names['c']
, which would return Carrot
.
Is there a similar solution in Java that does not involve using Map? Something comparable to the example above?
In Java, we can accomplish something similar by creating a String array like this:
String[] names= { "Apple","Banana", "Carrot" };
We can then access a specific element by calling names[2]
, and this will also return Carrot
.
I am searching for a solution in Java that functions in a manner akin to this.