How to store an array of pairs in Java?

前端 未结 9 1372
日久生厌
日久生厌 2020-12-15 06:51

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

        
9条回答
  •  忘掉有多难
    2020-12-15 07:23

    Couldn't you just use

    public class MyClass extends ArrayList{
    private A first;
    private B second;
    public MyClass(A first, B second){
    super();
    this.first = first;
    this.second = second;}
    }
    

    and then add some form of add method, along with a first and second accessor & mutator method? I'm sort of new to programming, but this way would seem like it might work, and be accessible to things other than just the DOUBLE, (in case down the road you want to use other types, like Integer, or even String).

提交回复
热议问题