Groovy – parseInt()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
parseXxx()

This method is used to get the primitive data type of a certain String. parseXxx() is a static method and can have one argument or two.

Syntax

static int parseInt(String s)
  
static int parseInt(String s, int radix)

Parameters

  • s − This is a string representation of decimal.
  • radix − This would be used to convert String s into integer.

Return Value

  • parseInt(String s) − This returns an integer (decimal only).
  • parseInt(int i) − 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.

Example

Following is an example of the usage of this method −

class Example {
   static void main(String[] args) { 
      int x = Integer.parseInt("9");
      double y = Double.parseDouble("5");
      int z = Integer.parseInt("444",16);
		
      System.out.println(x);
      System.out.println(y);
      System.out.println(z);
   } 
} 

When we run the above program, we will get the following result −

9 
5.0 
1092

Previous Page:-Click Here

Leave a Reply