How to store an array of pairs in Java?

前端 未结 9 1334
日久生厌
日久生厌 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:43

    Is Entry a class you defined? You instantiate it with new.

    Entry pair = new Entry(d1, d2);
    

    Note I am assuming you defined a constructor that takes 2 doubles, and you have references for d1 and d2.

    I suggest you NOT use the Map.Entry class. The semantics for that class are such that the values are a key and a value, fitting with the way Maps work.

提交回复
热议问题