long in java example

Android development

long is 64 bit signed type and used when int is not large enough to hold the value.

long je celé číslo 64 bitů -9223372036854775808 +9223372036854775807 a používá se tam, kde typ int není schopen pojmout takovou hodnotu čísla.

		// declaration and assignment of value type long
		long n = 22337203685477580L;
		// print formated value
		System.out.printf("The value of x is %d%n", n); // 22337203685477580
		System.out.format("%+,8d%n%n", n); // +22 337 203 685 477 580
 
		// declaring more variables in single statement
		long lo1 = 12L, lo2 = 56, lo3 = 1455555555589L;
 
		// long range of value
		System.out.println(Long.MAX_VALUE); // 9223372036854775807
		System.out.println(Long.MIN_VALUE); // -9223372036854775808
 
		// check if a string is a valid number in Java example
		// convert string to long Java example
		String sLong = "1288888888888888";
		long longParse = Long.parseLong(sLong);
 
		// convert strings to numbers
		long longFromString = (Long.valueOf(sLong)).longValue();
 
		// long to string in Java example code
		Long longObj = new Long(229999999999L);
		String str = longObj.toString();
		// else
		Long longS = 888888888888L;
		String strLong = longS.toString();
 
		// compare two long variables
		Long longComp1 = 5555L;
		if (longComp1.equals(55555555L))
			System.out.print("true");
 
		// compares the two specified long values in Java example
 
		int i = longS.compareTo(444444L); // -1 first < second
		// 0 first == second
		// 1 first > second
		System.out.print(i);
This entry was posted in Android Examples Code and tagged , , . Bookmark the permalink.


Comments are closed.



10,295 views