New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs

Java Integer getInteger(String nm) Method

Java getInteger(String nm) method is a part of the Integer Class of the java.lang package. This method is used to determine the integer value that is associated with the system property passed as the string argument. In case, there is no system property attached with the passed string then null is returned.

Syntax:

public static Integer getInteger(String nm)

Parameter:

The parameter passed is a String nm with which a system property is associated and the integer value of the same system property is to be determined.

Returns:

The integer value of the system property associated with the passed string argument.

Example 1:

Here, String s1 "sun.arch.data.model" is a system property that determines the version of JVM used. String s2 "StudyTonight" has no system property associated with it, hence null is returned.

We can access the System Properties through the System.getProperty(java.lang.String)

However, we can also create our own System property using the System.setProperty(String s, int n) as shown below:

import java.lang.Integer;

public class StudyTonight 
{  
    public static void main(String[] args)
       {          
          
          String s1 = "sun.arch.data.model";  
          System.out.println("Integer Value = "+Integer.getInteger(s1));  // It determines the integer value of the system property       
          
          String s2 = "StudyTonight"; //will return null because no system property is attached with this string 
          System.out.println("Integer Value = "+Integer.getInteger(s2));  
          
          System.setProperty("st.java", "23");  //set a custom property  
          System.out.println("Integer Value = " +Integer.getInteger("st.java"));  
        }  
}


Integer Value = 64
Integer Value = null
Integer Value = 23

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner;  

public class StudyTonight
{  
    public static void main(String[] args) 
    {  
        
        try
        {
          System.out.print("Enter the string value: ");  
          Scanner sc = new Scanner(System.in);  
          String s= sc.next();         
          System.out.println("Integer Value = "+Integer.getInteger(s));  //determines the integer value of the system property    
          
        }
        catch(Exception e)
        {
          System.out.println("Invalid Input!!");
        }
}   }


Enter the string value: sun.arch.data.model
Integer Value = 64
*************************************************
Enter the string value: mohit
Integer Value = null

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.