Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6786475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:14:59+00:00 2026-05-26T17:14:59+00:00

Let’s consider the following code snippet in Java. There are some of possible approaches

  • 0

Let’s consider the following code snippet in Java. There are some of possible approaches (that I know) to parse a String value to other numeric types (Let’s say for the sake of simplicity, it is an Integer, a wrapper type in Java).

package parsing;

final public class Parsing
{
    public static void main(String[] args)
    {
        String s="100";

        Integer temp=new Integer(s);
        System.out.print("\ntemp = "+temp);

        temp=Integer.parseInt(s);
        System.out.print("\ntemp = "+temp);        

        temp=Integer.valueOf(s).intValue();
        System.out.print("\ntemp = "+temp);

        temp=Integer.getInteger(s);
        System.out.print("\ntemp = "+temp);
    }    
}

In all the cases except the last one, returns the value 100 after converting it into an Integer. Which one is the best approach to parse a String value to other numeric types available in Java? The last case returns NULL even if the String object s already contains a parsable value. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:15:00+00:00Added an answer on May 26, 2026 at 5:15 pm

    Calling Integer.getInteger("42") attempts to fetch the value of the system property whose name is “42”. Unless you really do have a system property with that name, it will return null.

    Here is the Java 7 javadoc if you want more details.

    Yes, the name of the method is misleading, and its utility is questionable.


    FWIW, I’d use Integer.parseInt(String) if I required an int result and Integer.valueOf(String) if I required an Integer. I’d only use new Integer(String) if I required the object to be a new Integer and not one that might be shared.

    (The reasoning is the same as for new Integer(int) versus Integer.valueOf(int). Again, read the javadocs for a more complete explanation.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider the following expressions in Java. byte a = 32; byte b =
Let's say that I have an arbitrary string like `A man + a plan
Let's say i have an android device that has some extra buttons on it,
Let's say I have the following code: Sub TestRangeLoop() Dim rng As Range Set
Let me start off by stating that I know the assignment operator in C#
Let's say I have the following within my source code, and I want to
Let me know the best way to serialize my Java object Download. This is
Let's say I have some json like this in mongo: {n:5} and a java
Let's say I have the following type type Key = String type Score =
Let's say you have a class called Customer, which contains the following fields: UserName

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.