Convert Java
String to Long
public class
StringToLongExample
{
public static
void main(String[] args)
{
Long lObj1 = new
Long("100");
System.out.println(lObj1);
String str =
"100";
Long lObj2 =
Long.valueOf(str);
System.out.println(lObj2);
}
}
Convert Long
object to String object
public class
LongToStringExample
{
public static void
main(String[] args)
{
Long lObj = new
Long(10);
String str =
lObj.toString();
System.out.println("Long
converted to String as " + str);
}
}
Convert Long to
numeric primitive data types
public class
LongToNumericPrimitiveTypesExample
{
public static void
main(String[] args)
{
Long lObj = new
Long("10");
byte b =
lObj.byteValue();
System.out.println(b);
short s =
lObj.shortValue();
System.out.println(s);
int i = lObj.intValue();
System.out.println(i);
float f =
lObj.floatValue();
System.out.println(f);
double d =
lObj.doubleValue();
System.out.println(d);
}
}
Convert String
to long
public class
StringToPrimitiveLongExample
{
public static void
main(String[] args)
{
String str = new
String("10");
long l =
Long.parseLong(str);
System.out.println(l);
}
}
Convert long
primitive to Long object
public class
longToLongExample
{
public static void
main(String[] args)
{
long i = 10;
Long lObj = new
Long(i);
System.out.println(lObj);
}
}
Java Long
public class
LongExample
{
public static void
main(String[] args)
{
long l = 10;
Long longObj1 = new
Long(l);
Long longObj2 = new
Long("5");
System.out.println(longObj1);
System.out.println(longObj2);
}
}
Find absolute
value of float, int, double and long using Math
public class
FindAbsoluteValueExample
{
public static void
main(String[] args)
{
int i = 8;
int j = -5;
System.out.println("Absolute
value of " + i + " is :" + Math.abs(i));
System.out.println("Absolute
value of " + j + " is :" + Math.abs(j));
float f1 = 10.40f;
float f2 = -50.28f;
System.out.println("Absolute
value of " + f1 + " is :" + Math.abs(f1));
System.out.println("Absolute
value of " + f2 + " is :" + Math.abs(f2));
double d1 = 43.324;
double d2 = -349.324;
System.out.println("Absolute
value of " + d1 + " is :" + Math.abs(d1));
System.out.println("Absolute
value of " + d2 + " is :" + Math.abs(d2));
long l1 = 34;
long l2 = -439;
System.out.println("Absolute
value of " + l1 + " is :" + Math.abs(l1));
System.out.println("Absolute
value of " + l2 + " is :" + Math.abs(l2));
}
}
No comments:
Post a Comment