如何在 JavaTuples 中設定八位位元組值
要在 Java 中設定八位位元組值,需要使用 setAtX() 方法。其中,X 是需要設定值的下標,例如要在下標 1 處設定值,可使用 setAt1() 和值為引數。
首先讓我們看看在 JavaTuples 中需要做些什麼。要使用 JavaTuples 中的八位位元組類,需要匯入以下資料包 −
import org.javatuples.Octet;
注意 − 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果你正在使用 Eclipse IDE,請右鍵單擊專案-> 屬性-> Java 構建路徑-> 新增外部 Jar 並上傳下載的 JavaTuples Jar 檔案。有關執行 JavaTuples 的所有步驟,請參閱以下指南 −
步驟: 如何在 Eclipse 中執行 JavaTuples 程式
以下是如何在 Java 中設定八位位元組值的一個示例 −
示例
import org.javatuples.Octet; public class Demo { public static void main(String[] args) { Octet<String, String, String, String, String, String, String, String> oc = Octet.with( "laptop", "desktop","mobile", "tablet","monitor", "LCD","LED", "OLED"); // index 0 System.out.println(oc.setAt0("SSD")); // index 1 System.out.println(oc.setAt1("HDD")); // index 4 System.out.println(oc.setAt4("Pen Drive")); // index 5 System.out.println(oc.setAt5("Headphone")); } }
輸出
[SSD, desktop, mobile, tablet, monitor, LCD, LED, OLED] [laptop, HDD, mobile, tablet, monitor, LCD, LED, OLED] [laptop, desktop, mobile, tablet, Pen Drive, LCD, LED, OLED] [laptop, desktop, mobile, tablet, monitor, Headphone, LED, OLED]
廣告