|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:57
/*
* Convert String to Integer example. Program to convert Java
* String object to Integer object.
*/
public class StringToInteger {
public static void main(String args[]){
//new String object
String str = new String("47");
//Use Integer(String) constructor
Integer iObj1 = new Integer(str);
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:56
/*
* Convert String to primitive int example. Program to convert Java
* String object to primitive int data type.
*/
public class StringToInt {
public static void main(String args[]){
//new String object
String str = new String("342");
/*
* To convert String to primitive int data type, use
* parseInt(String) static method of Integer class
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:55
/*
* Convert Integer to String example. Program to convert Java
* Integer object to String object.
*/
public class IntegerToString {
public static void main(String args[]){
//new Integer object
Integer iObj = new Integer("12");
//to convert Integer to String use toString method of Integer wrapper class
String strBValue = iObj.toString();
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:54
/*
* Convert Integer to primitive int example.
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:50
/*
* Convert String to primitive double example. Program to convert Java
* String object to primitive double data type.
*/
public class StringToPrimitiveDouble {
public static void main(String args[]){
//new String object
String str = new String("43.21");
/*
* To convert String to primitive double data type, use
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:49
/*
* Convert String to Double example. Program to convert Java
* String object to Double object.
*/
public class StringToDouble {
public static void main(String args[]){
//new String object
String str = new String("16.85");
//Use Double(String) constructor
Double dObj1 = new Double(str);
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:49
/*
* Convert Double to String example. Program to convert Java
* Double object to String object.
*/
public class DoubleToString {
public static void main(String args[]){
//new Double object
Double dObj = new Double("1.543");
//to convert Double to String use toString method of Double wrapper class
String strDValue = dObj.toString();
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:48
/*
* Convert double primitive to Double Object example. Program to convert Java
* double primitive data type to Double object.
*/
public class DoublePrimitiveToDouble {
public static void main(String args[]){
//new double primitive
double d = 5.74;
//Use Double(double d) constructor
Double dObj1 = new Double(d);
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:47
/*
* Convert String to primitive byte example. Program to convert Java
* String object to primitive byte data type.
*/
public class StringToPrimitiveByte {
public static void main(String args[]){
//new String object
String str = new String("2");
/*
* To convert String to primitive byte data type, use
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:47
/*
* Convert String to Byte example. Program to convert Java
* String object to Byte object.
*/
public class StringToByte {
public static void main(String args[]){
//new String object
String str = new String("2");
//Use Byte(String) constructor
Byte bObj1 = new Byte(str);
//OR Use static valueOf(String) method of Byte class
|
|