Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Rahimv's blog

Rahimv's picture

Convert String to Integer example

1
Your rating: None Average: 1 (1 vote)
  1. /*
  2.  * Convert String to Integer example. Program to convert Java
  3.  * String object to Integer object.
  4.  */
  5.  
  6. public class StringToInteger {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("47");
  12.  
  13.   //Use Integer(String) constructor
  14.   Integer iObj1 = new Integer(str);
  15.  
Rahimv's picture

Convert String to primitive int example

5
Your rating: None Average: 5 (1 vote)
  1. /*
  2.  * Convert String to primitive int example. Program to convert Java
  3.  * String object to primitive int data type.
  4.  */
  5.  
  6. public class StringToInt {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("342");
  12.  
  13.   /*
  14.    * To convert String to primitive int data type, use
  15.    * parseInt(String) static method of Integer class
Rahimv's picture

Convert Integer to String example

0
Your rating: None
  1. /*
  2.  * Convert Integer to String example. Program to convert Java
  3.  * Integer object to String object.
  4.  */
  5.  
  6. public class IntegerToString {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new Integer object
  11.   Integer iObj = new Integer("12");
  12.  
  13.   //to convert Integer to String use toString method of Integer wrapper class
  14.   String strBValue = iObj.toString();
  15.  
Rahimv's picture

Convert Integer to primitive int example

2
Your rating: None Average: 2 (2 votes)
  1. /*
  2.  * Convert Integer to primitive int example.
Rahimv's picture

Convert String to primitive double example

0
Your rating: None
  1. /*
  2.  * Convert String to primitive double example. Program to convert Java
  3.  * String object to primitive double data type.
  4.  */
  5.  
  6. public class StringToPrimitiveDouble {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("43.21");
  12.  
  13.   /*
  14.    * To convert String to primitive double data type, use
Rahimv's picture

Convert String to Double example

0
Your rating: None
  1. /*
  2.  * Convert String to Double example. Program to convert Java
  3.  * String object to Double object.
  4.  */
  5.  
  6. public class StringToDouble {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("16.85");
  12.  
  13.   //Use Double(String) constructor
  14.   Double dObj1 = new Double(str);
  15.  
Rahimv's picture

Convert Double to String example

0
Your rating: None
  1. /*
  2.  * Convert Double to String example. Program to convert Java
  3.  * Double object to String object.
  4.  */
  5.  
  6. public class DoubleToString {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new Double object
  11.   Double dObj = new Double("1.543");
  12.  
  13.   //to convert Double to String use toString method of Double wrapper class
  14.   String strDValue = dObj.toString();
  15.  
Rahimv's picture

Convert double primitive to Double Object example

0
Your rating: None
  1. /*
  2.  * Convert double primitive to Double Object example. Program to convert Java
  3.  * double primitive data type to Double object.
  4.  */
  5.  
  6. public class DoublePrimitiveToDouble {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new double primitive
  11.   double d = 5.74;
  12.  
  13.   //Use Double(double d) constructor
  14.   Double dObj1 = new Double(d);
  15.  
Rahimv's picture

Convert String to primitive byte example

0
Your rating: None
  1. /*
  2.  * Convert String to primitive byte example. Program to convert Java
  3.  * String object to primitive byte data type.
  4.  */
  5.  
  6. public class StringToPrimitiveByte {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("2");
  12.  
  13.   /*
  14.    * To convert String to primitive byte data type, use
Rahimv's picture

Convert String to Byte example

0
Your rating: None
  1. /*
  2.  * Convert String to Byte example. Program to convert Java
  3.  * String object to Byte object.
  4.  */
  5.  
  6. public class StringToByte {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("2");
  12.  
  13.   //Use Byte(String) constructor
  14.   Byte bObj1 = new Byte(str);
  15.  
  16.   //OR Use static valueOf(String) method of Byte class
Syndicate content