Share on Google+Share on Google+

Convert String to Number

In this section, we will learn how to convert String to Number.

Convert String to Number


In this section, we will learn how to convert String to Number. The following program provides you the functionality to convert String to Number.

Code Description:

In this program we have taken a String of int, byte, boolean, double as shown below and also we have used the method MIN
_VALUE and MAX_VALUE of different wrapper classes to print all the values on int, short, double etc. 

Here is the code of the program:

public class StrToNum{
  public static void main (String args[]){
  String table = "Table of the Java Numbers\n" +
 "Primitive Type\tSize in Bits\tTypical Value\tMinimum Value
\tMaximum Value\n" 
  // int
  table += "int\t\t" 32 "\t\t" 65536 "\t\t" + Integer.MIN_VALUE
"\t" + Integer.MAX_VALUE + "\n";
  // byte
  table += "byte\t\t" "\t\t" (byte)"\t\t" + Byte.MIN_VALUE 
"\t\t" + Byte.MAX_VALUE + "\n";
  // short
  table += "short\t\t" 16 "\t\t" (short)1024 "\t\t" + Short.MIN_VALUE
"\t\t" + Short.MAX_VALUE + "\n";
  table += "boolean\t\t" "\t\t" true ',' false "\t\t" "\n";
  // double
  table += "double\t\t" 64 "\t\t" 100e100 "\t\t" + Double.MIN_VALUE +
"\t" + Double.MAX_VALUE + "\n";
  table +=


Output of the program:


C:\unique>java StrToNum
Formatable of the Java Numbers
Primitive Type   Size in Bits  Typical Value  Minimum Value   Maximum Value
************** ************** ************** ************** **************
int   32  65536   -2147483648  2147483647
byte  8  5   -128  127
short  16  1024  -32768  32767
boolean   true,false
double   64  1.0E102   4.9E-324   1.79769313486231
************** ************** ************** *************** ************


Download this example.



Posted on: May 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Convert String to Number  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image