使用JavaTuples在Java中从Septet类实现八位类
首先创建Septet并添加元素-
Septet<String, String, String, String, String, String, String> septet = new Septet<String, String, String, String, String, String, String>( "Laptop", "Desktop", "Tablet", "Notebook", "Phone", "Reader", "LCD");
现在,从Septet实现Octet-
Octet<String, String, String, String, String, String, String, String> octet = septet.add("LED");
以下是在Java中从Septet类实现Octet类的示例-
示例
import org.javatuples.Septet; import org.javatuples.Octet; public class MyDemo { public static void main(String[] args) { Septet<String, String, String, String, String, String, String> septet = new Septet<String, String, String, String, String, String, String>( "Laptop", "Desktop", "Tablet", "Notebook", "Phone", "Reader", "LCD"); System.out.println("Septet elements = " + septet); Octet<String, String, String, String, String, String, String, String>octet = septet.add("LED"); System.out.println("Octet (implemented from Septet) = " + octet); } }
输出结果
Septet elements = [Laptop, Desktop, Tablet, Notebook, Phone, Reader, LCD] Octet (implemented from Septet) = [Laptop, Desktop, Tablet, Notebook, Phone, Reader, LCD, LED]