定义包含Java中三元组的Array

Lon*_*guy 1 java data-structures

我想定义一个包含三元组的数组,例如Array a = {{1,2,3},{3,4,5},{5,6,7}};

我如何用Java做到这一点?我应该使用什么数据结构?

Dav*_*ano 5

创建一个实现三元组的类,然后创建一个新的Triplet对象的数组:

public class Triplet {
   private int first;
   private int second;
   private int third:

   public Triplet(int f, int s, int t) {
       first = f;
       second = s;
       third = t;
   }

/*** setters and getters defined here ****/

}
Run Code Online (Sandbox Code Playgroud)

然后定义Triplet类型的数组:

Triplet[] tripletsArray = new Triplet[size];
Run Code Online (Sandbox Code Playgroud)