Ad Home

Theme images by kelvinjay. Powered by Blogger.

Travel

Header Ads

Java

Selenium

UFT

Framework

General QA Concept

BDD

» » » How Integer.ParseInt Method Works In Java

Integer.ParseInt is very commonly used method in java.The parameter to this method will be String. So It works on String only.But what kind of String??
Those which can represent ASCII values for digit(0-...9). Remember Integer.ParseInt only works on string representation of numeric value but not something like "five".

int x=Integer.parseInt("9");
//valid
int y=Integer.parseInt("nine");
//invalid compilation error

Let us check the syntax:

  • static int parseInt(String s) // here s is the string representation of Numeric value
  • static int parseInt(String s, int radix) //This returns an integer, given a string representation of decimal, binary, octal, or hexadecimal (radix equals 10, 2, 8, or 16 respectively) numbers as input.
Let us check out one example:

public class parseTest{ 

   public static void main(String args[]){
      int x =Integer.parseInt("5");
      double c = Double.parseDouble("8");
      int b = Integer.parseInt("444",16);

      System.out.println(x);
      System.out.println(c);
      System.out.println(b);
   }


Output
5
8.00
1092

«
Next
Newer Post
»
Previous
Older Post

No comments:

Leave a Reply