Convert byte to
Byte object
public class
byteToByteExample
{
public static void
main(String[] args)
{
byte i = 10;
Byte bObj = new Byte(i);
System.out.println(bObj);
}
}
Java Byte
public class ByteExample
{
public static void
main(String[] args)
{
byte b = 10;
Byte bObj1 = new Byte(b);
Byte bObj2 = new
Byte("4");
System.out.println(bObj1);
System.out.println(bObj2);
}
}
Convert Double
object to String object
public class
JavaDoubleToStringExample
{
public static void
main(String[] args)
{
Double dObj = new Double(10.25);
String str =
dObj.toString();
System.out.println("Double
converted to String as " + str);
}
}
Convert Java
String to Double
public class
JavaStringToDoubleExample
{
public static void
main(String[] args)
{
Double dObj1 = new
Double("100.564");
System.out.println(dObj1);
String str1 =
"100.476";
Double dObj2 =
Double.valueOf(str1);
System.out.println(dObj2);
String str2 =
"76.39";
double d =
Double.parseDouble(str2);
System.out.println(d);
}
}
Convert java
Double to numeric primitive data types
public class
JavaDoubleToNumericPrimitiveTypesExample
{
public static void
main(String[] args)
{
Double dObj = new
Double("10.50");
byte b = dObj.byteValue();
System.out.println(b);
short s =
dObj.shortValue();
System.out.println(s);
int i = dObj.intValue();
System.out.println(i);
float f =
dObj.floatValue();
System.out.println(f);
double d =
dObj.doubleValue();
System.out.println(d);
}
}
Convert java
double to Double object
public class
JavadoubleToDoubleExample
{
public static void main(String[]
args)
{
double d = 10.56;
Double dObj = new
Double(d);
System.out.println(dObj);
}
}
Java Double
compare
public class
JavaDoubleCompareExample
{
public static void
main(String[] args)
{
double d1 =
5.35;
double d2 = 5.34;
int i1 = Double.compare(d1,d2);
if(i1 > 0)
{
System.out.println("First
is grater");
}
else if(i1 < 0)
{
System.out.println("Second
is grater");
}
else
{
System.out.println("Both
are equal");
}
Double dObj1 = new
Double("5.35");
Double dObj2 = new
Double("5.34");
int i2 =
dObj1.compareTo(dObj2);
if(i2 > 0)
{
System.out.println("First
is grater");
}
else if(i2 < 0)
{
System.out.println("Second
is grater");
}
else
{
System.out.println("Both
are equal");
}
}
}
No comments:
Post a Comment