Examples for usage of all methods of 'java.lang.Long' with console output of example code.
Please click on method from below list to go to code example for usage of that method. Click [↓ Imports] to get import statements used in examples. To read javadoc of methods, click on [⿺ Javadoc] for that method.
long one = 1l;
int bitCountOne = Long.bitCount(one);
System.out.println(bitCountOne);
long zero = 0l;
int bitCountZero = Long.bitCount(zero);
System.out.println(bitCountZero);
long minusone = -1l;
int bitCountMinusOne = Long.bitCount(minusone);
System.out.println(bitCountMinusOne);
long max = Long.MAX_VALUE;
int bitCountMax = Long.bitCount(max);
System.out.println(bitCountMax);
long min = Long.MIN_VALUE;
int bitCountMin = Long.bitCount(min);
System.out.println(bitCountMin);
Output: 1 0 64 63 1
Tag: Example for bitCount method of class java.lang.Long., Long bitCount function example with arguments long arg0, How to use bitCount method of Long?, Usage of Long.bitCount, Long.bitCount() examples
Long one = 1l;
byte oneByte = one.byteValue();
System.out.printf("Byte value of 1 = 0x%02X \n", oneByte);
Long zero = 0l;
byte zeroByte = zero.byteValue();
System.out.printf("Byte value of 0 = 0x%02X \n", zeroByte);
Long minuesone = -1l;
byte minuesoneByte = minuesone.byteValue();
System.out.printf("Byte value of -1 = 0x%02X \n", minuesoneByte);
Long max = Long.MAX_VALUE;
byte maxByte = max.byteValue();
System.out.printf("Byte value of MAX = 0x%02X \n", maxByte);
Long min = Long.MIN_VALUE;
byte minByte = min.byteValue();
System.out.printf("Byte value of MIN = 0x%02X \n", minByte);
Output: Byte value of 1 = 0x01 Byte value of 0 = 0x00 Byte value of -1 = 0xFF Byte value of MAX = 0xFF Byte value of MIN = 0x00
Tag: Example for byteValue method of class java.lang.Long., Long byteValue function example , How to use byteValue method of Long?, Usage of Long.byteValue, Long.byteValue() examples, How to convert Long to Byte or Hex
long ten1 = 10l;
long ten2 = 10l;
long hundred = 100l;
long minsHundred = -100l;
System.out.println("Compare 10 10 --> " + Long.compare(ten1, ten2));
System.out.println("Compare 100 10 --> " + Long.compare(hundred, ten1));
System.out.println("Compare 10 100 --> " + Long.compare(ten1, hundred));
System.out.println("Compare -100 10 --> " + Long.compare(minsHundred, ten1));
System.out.println("Compare 10 -100 --> " + Long.compare(ten1, minsHundred));
Output: Compare 10 10 --> 0 Compare 100 10 --> 1 Compare 10 100 --> -1 Compare -100 10 --> -1 Compare 10 -100 --> 1
Tag: Example for compare method of class java.lang.Long., Long compare function example with arguments long arg0, long arg1, How to use compare method of Long?, Usage of Long.compare, Long.compare() examples
Long ten1 = 10l;
Long ten2 = 10l;
Long hundred = 100l;
Long minsHundred = -100l;
System.out.println("Compare 10 10 --> " + ten1.compareTo(ten2));
System.out.println("Compare 100 10 --> " + hundred.compareTo(ten1));
System.out.println("Compare 10 100 --> " + ten1.compareTo(hundred));
System.out.println("Compare -100 10 --> " + minsHundred.compareTo(ten1));
System.out.println("Compare 10 -100 --> " + ten1.compareTo(minsHundred));
Output: Compare 10 10 --> 0 Compare 100 10 --> 1 Compare 10 100 --> -1 Compare -100 10 --> -1 Compare 10 -100 --> 1
Tag: Example for compareTo method of class java.lang.Long., Long compareTo function example with arguments java.lang.Long arg0, How to use compareTo method of Long?, Usage of Long.compareTo, Long.compareTo() examples
long ten1 = 10l;
long ten2 = 10l;
long hundred = 100l;
long minsHundred = -100l;
System.out.println("Compare Unsigned 10 10 --> " + Long.compareUnsigned(ten1, ten2));
System.out.println("Compare Unsigned 100 10 --> " + Long.compareUnsigned(hundred, ten1));
System.out.println("Compare Unsigned 10 100 --> " + Long.compareUnsigned(ten1, hundred));
System.out.println("Compare Unsigned -100 10 --> " + Long.compareUnsigned(minsHundred, ten1));
System.out.println("Compare Unsigned 10 -100 --> " + Long.compareUnsigned(ten1, minsHundred));
Output: Compare Unsigned 10 10 --> 0 Compare Unsigned 100 10 --> 1 Compare Unsigned 10 100 --> -1 Compare Unsigned -100 10 --> 1 Compare Unsigned 10 -100 --> -1
Tag: Example for compareUnsigned method of class java.lang.Long., Long compareUnsigned function example with arguments long arg0, long arg1, How to use compareUnsigned method of Long?, Usage of Long.compareUnsigned, Long.compareUnsigned() examples
// Decode decimal
Long hundred = Long.decode("100");
System.out.println("Decimal decoded = " + hundred);
Long minusHundred = Long.decode("-100");
System.out.println("Decimal decoded = " + minusHundred);
// Decode Hex
Long hundredHex = Long.decode("0x64");
System.out.println("Hex decoded = " + hundredHex);
Long minusHundredHex = Long.decode("-0x64");
System.out.println("Hex decoded = " + minusHundredHex);
Long hundredHexHash = Long.decode("#64");
System.out.println("Hex decoded = " + hundredHexHash);
Long minusHundredHexHash = Long.decode("-#64");
System.out.println("Hex decoded = " + minusHundredHexHash);
// Decode Octal
Long hundredOctal = Long.decode("0144");
System.out.println("Octal decoded = " + hundredOctal);
Long minusHundredOctal = Long.decode("-0144");
System.out.println("Octal decoded = " + minusHundredOctal);
Output: Decimal decoded = 100 Decimal decoded = -100 Hex decoded = 100 Hex decoded = -100 Hex decoded = 100 Hex decoded = -100 Octal decoded = 100 Octal decoded = -100
Tag: Example for decode method of class java.lang.Long., Long decode function example with arguments java.lang.String arg0, How to use decode method of Long?, Usage of Long.decode, Long.decode() examples, How to convert Hex to Long in Java., How to convert or parse Octal String into Long primitive in Java?, How to convert Hexadcimal or decimal to Long primitive in Java?
long hundred = 100l;
long minusHundred = -100l;
long ten = 10l;
System.out.println(Long.divideUnsigned(hundred, ten));
// Minus hundred is treated as unsigned long value.
System.out.println(Long.divideUnsigned(minusHundred, ten));
Output: 10 1844674407370955151
Tag: Example for divideUnsigned method of class java.lang.Long., Long divideUnsigned function example with arguments long arg0, long arg1, How to use divideUnsigned method of Long?, Usage of Long.divideUnsigned, Long.divideUnsigned() examples
Long thousand = 1000l;
double thousandDouble = thousand.doubleValue();
System.out.println("Double of " + thousand + " = " + thousandDouble);
Long zero = 0l;
double zeroDouble = zero.doubleValue();
System.out.println("Double of " + zero + " = " + zeroDouble);
Long min = Long.MIN_VALUE;
System.out.println(Long.MIN_VALUE + " converted to " + min.doubleValue());
Long max = Long.MAX_VALUE;
System.out.println(Long.MAX_VALUE + " converted to " + max.doubleValue());
Output: Double of 1000 = 1000.0 Double of 0 = 0.0 -9223372036854775808 converted to -9.223372036854776E18 9223372036854775807 converted to 9.223372036854776E18
Tag: Example for doubleValue method of class java.lang.Long., Long doubleValue function example , How to use doubleValue method of Long?, Usage of Long.doubleValue, Long.doubleValue() examples
Tag: Simple working examples of methods / functions of class java.lang.Long along with their console output, java.lang.Long tutorial., Guide to java.lang.Long & its methods., Understanding java.lang.Long with examples.