使用JavaTuples用Triplet类实现Quartet类


以下是使用JavaTuples从Triplet类实现Quartet类的示例 −

示例

import org.javatuples.Triplet;
import org.javatuples.Quartet;
public class MyDemo {
   public static void main(String[] args) {
      Triplet<String, String, String>triplet = new Triplet<String, String, String>("Gray", "Blue", "Gray100");
      System.out.println("Triplet elements = " + triplet);
      Quartet<String, String, String, String>quartet = triplet.add("Blue30");
      System.out.println("Quartet (Implemented from Triplet) = " + quartet);
   }
}

输出

Triplet elements = [Gray, Blue, Gray100]
Quartet (Implemented from Triplet) = [Gray, Blue, Gray100, Blue30]

现在让我们看另一个从Triplet实现Quartet类的示例。这在第3个位置插入元素 −

示例

import org.javatuples.Triplet;
import org.javatuples.Quartet;
public class MyDemo {
   public static void main(String[] args) {
      Triplet<String, String, String>triplet = new Triplet<String, String, String>("Gray", "Blue", "Gray100");
      System.out.println("Triplet elements = " + triplet);
      Quartet<String, String, String, String>quartet = triplet.addAt2("Blue30");
      System.out.println("Quartet (Implemented from Triplet) = " + quartet);
   }
}

输出

Triplet elements = [Gray, Blue, Gray100]
Quartet (Implemented from Triplet) = [Gray, Blue, Blue30, Gray100]

更新时间:24-9-2019

79次浏览

开启您的职业生涯

通过完成课程获得认证

开始
广告