I have the below code:
Map<String, Map<Double, String>> map = new HashMap<>(); Map<Double,String> Amap = new HashMap<>(); map.put(getValuesTypes.FUT(), HERE);
Instead of creating a Map first and put it at "HERE", I'm looking for a function like I could use with a List
there Arrays.asList(...)
so that i can just enter at "Here" ?.asMap({1.0,"A"}, {2.0,"B"})
The method only creates a List wrapper upon the underlying array. Because of which, both the array and the newly created list continue to refer to the exact same elements. That is why, no elements are copied when we use asList method.
The asList() method of java. util. Arrays class is used to return a fixed-size list backed by the specified array. This method acts as a bridge between array-based and collection-based APIs, in combination with Collection.
Duplicate keys are not allowed in a Map. Basically, Map Interface has two implementation classes HashMap and TreeMap the main difference is TreeMap maintains an order of the objects but HashMap will not. HashMap allows null values and null keys. Both HashSet and HashMap are not synchronized.
asList returns a fixed-size list that is backed by the specified array; the returned list is serializable and allows random access.
You can initialize HashMap
like this.
new HashMap<Double, String>() { { put(1.0, "ValA"); put(2.0, "ValB"); } };
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