I am new to Java, I want to store an array of pair of doubles. My code looks like this:
import java.util.ArrayList;
import java.util.Map.Entry;
List<Entry<Double, Double>> values = new ArrayList<>();
Entry<Double, Double> pair;
// set pair values:
// pair.setKey(0.5); // this method does not exists
// pair.setValue(3.6);
values.add(pair);
How can I initialize the pair variable?
Is there a better structure to store my array of pair of doubles?
Create your own class to represent a pair and add a constructor that takes two arguments:
See this answer for reasons why a
Pairdoes not exist in Java: What is the equivalent of the C++ Pair<L,R> in Java?