First, create a Pair
class:
//A and B are generics
class Pair<A, B> {
private A element1;
private B element2;
public Pair(A element1, B element2) {
this.element1 = element1;
this.element2 = element2;
}
//public getters...
}
Second, have a Map<Float, List<Pair<A, B>>>
to insert your key/value:
Map<Float, List<Pair<A, B>>> table = new HashMap<Float, List<Pair<A, B>>>();
Third, create a List<Pair<A, B>>
backed by LinkedList<Pair<A, B>>
:
List<Pair<A, B>> myList = new LinkedList<Pair<A, B>>();
Fourth, add your list into your map.
table.put(1, myList);
You should not use LinkedList
nor HashMap
classes directly, instead try to code oriented to interfaces. Also, I would recommend you to use another key instead Float
or Double
since their values may differ due to floating point comparison. I would recommend Integer
, Long
, String
or BigDecimal
instead of Float
.