「Java」Longクラスのcompare()とbyteValue()のサンプル
書式
public byte byteValue()
このLongの縮小プリミティブ変換後の値をbyteとして返します
public static int compare(long x,long y)
2つのlong値を数値的に比較します。
使用例
package com.arkgame.study;
public class LongDemo {
static void print() {
//変数の宣言
Long cftA = new Long(45);
Long cftB = new Long("66");
System.out.println("value1: " + cftA);
System.out.println("value2: " + cftB);
}
public static void main(String[] args) {
print();
// byteValue() 値をbyteとして返す
System.out.println("byteValue1: " + new Long(100).byteValue());
System.out.println("byteValue2: " + new Long(800).byteValue());
// compare(long x, long y) 数値を比較
System.out.println("result1: " + Long.compare(51, 62));
System.out.println("result2: " + Long.compare(71, 71));
System.out.println("result3: " + Long.compare(72, 61));
}
}
実行結果
value1: 45
value2: 66
byteValue1: 100
byteValue2: 32
result1: -1
result2: 0
result3: 1