使用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]
广告