Integer.ValueOf(line,16) converts string value line into an Integer object. In this case radix is 16.

intValue() gets the int value from the Integer object created above.

Furthermore, above two steps are equivalent to Integer.parseInt(line,16).

In order to get more INFO please refer Java API Documentation of Integer class.

Answer from Upul Bandara on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
April 21, 2026 - The characters in the string must all be decimal digits, except that the first character may be an an ASCII plus sign '+' ('\u002B'). The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseUnsignedInt(java.lang.String, int) method. Parameters: s - a String containing the unsigned int representation to be parsed · Returns: the unsigned integer value represented by the argument in decimal. Throws: NumberFormatException - if the string does not contain a parsable unsigned integer. Since: 1.8 · public static Integer valueOf(String s, int radix) throws NumberFormatException ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › integer-valueof-method-in-java
Integer valueOf() Method in Java - GeeksforGeeks
January 23, 2026 - Return Value : The method returns an Integer object holding the value represented by the string argument in the specified base or radix. Example 1: valueOf(String, radix) Java ·
🌐
Reddit
reddit.com › r/learnjava › integer.valueof() and parseint()
r/learnjava on Reddit: Integer.valueOf() and parseint()
September 14, 2023 -

Hello, i have started learning java recently by mooc. But during this course, it uses Integer.valueOf while taking integer inputs, I use same way but whenever i do it intellij suggests me parseint(). And I wonder if it is better to use parseint?

Top answer
1 of 3
9
Integer.parseInt() returns a primitive. valueOf() returns an Integer object. Call the one that matches the return type you need and avoid autoboxing/unboxing.
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.integer.valueof
Integer.ValueOf Method (Java.Lang) | Microsoft Learn
The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the #parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: <blockquote> Integer.valueOf(Integer.parseInt(s))</blockquote>
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 21 & JDK 21)
January 20, 2026 - If the property value begins with the two ASCII characters 0x or the ASCII character #, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as by the method valueOf(java.lang.String, int) with radix 16.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › integer_valueof_string.htm
Java - Integer valueOf(String s) method
The Java Integer valueOf(String s) method returns an Integer object holding the value of the specified String s.
Find elsewhere
🌐
Puredanger
puredanger.github.io › tech.puredanger.com › 2007 › 02 › 01 › valueof
Why YOU should use Integer.valueOf(int)
February 1, 2007 - But in JDK 5+, you should really use valueOf because Integer now caches Integer objects between -128 and 127 and can hand you back the same exact Integer(0) object every time instead of wasting an object construction on a brand new identical Integer object.
🌐
CodeGym
codegym.cc › java blog › java classes › java.lang.integer class
Java.lang.Integer Class
February 20, 2025 - static Integer valueOf(int i) returns an Integer whose value is i;
🌐
LabEx
labex.io › tutorials › java-how-to-utilize-the-integer-valueof-method-in-java-414178
How to utilize the Integer.valueOf() method in Java | LabEx
Integer i1 = Integer.valueOf("42"); Integer i2 = Integer.valueOf("42"); System.out.println(i1 == i2); // Output: true · In the above example, since both i1 and i2 are assigned the value 42, which is within the cached range, the method returns the same Integer object for both calls, resulting in improved memory usage and performance. LabEx, a leading provider of Java programming resources, strongly recommends using the Integer.valueOf() method as a best practice when working with integer values in your Java applications.
🌐
Codekru
codekru.com › home › integer.valueof() method in java with examples
Integer.valueOf() method in Java with Examples - Codekru
December 4, 2022 - public class Codekru { public static void main(String[] args) { String str = null; Integer i1 = Integer.valueOf(str); System.out.println("Integer value representing str: " + i1); } } ... Exception in thread "main" java.lang.NumberFormatException: null at java.base/java.lang.Integer.parseInt(Integer.java:614) at java.base/java.lang.Integer.valueOf(Integer.java:983)
🌐
LabEx
labex.io › tutorials › java-java-integer-valueof-method-117760
Mastering Java Integer ValueOf Method | LabEx
This method is part of the java.lang package and is used to return the equivalent Integer object of the integer primitive value passed as an argument. We will start by creating a Java class in the ~/project directory.
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.lang.Integer.html
Class java.lang.Integer
public static Integer valueOf(String s, int radix) throws NumberFormatException
🌐
Study.com
study.com › business courses › business 104: information systems and computer applications
How to Convert Int to String in Java - ValueOf Method | Study.com
We will use the valueOf method in Java to convert an int to a String. This method is actually built within the Java String class. Recall that Java not only lets you declare primitive data types (int, double, float), but it stores those in classes: Integer, Double, and String.
🌐
Redis
redis.io › docs › latest › commands
Commands | Docs
Decrements a number from the integer value of a key.
🌐
Oracle
docs.oracle.com › en › java › javase › 20 › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 20 & JDK 20)
July 10, 2023 - Integer.valueOf(val) : result; to avoid the unnecessary allocation of an Integer object when the default value is not needed. ... Returns the integer value of the system property with the specified name. The first argument is treated as the name of a system property.
🌐
Baeldung
baeldung.com › home › java › java string › integer.tostring() vs string.valueof() in java
Integer.toString() vs String.valueOf() in Java | Baeldung
April 7, 2025 - * @see java.lang.Integer#toString(int, int) */ public static String valueOf(int i) { return Integer.toString(i); } To understand it better, we’ll see a few examples where we pass signed/unsigned integers as parameters to it to understand integer to string conversion happens: @Test public void whenValidIntIsPassed_thenShouldConvertToValidString() { assertEquals("11", String.valueOf(11)); assertEquals("11", String.valueOf(+11)); assertEquals("-11", String.valueOf(-11)); } To summarize, there are no actual differences between these two methods, but we should understand the following points to avoid confusion.
🌐
Oracle
docs.oracle.com › javame › config › cldc › ref-impl › cldc1.0 › jsr030 › java › lang › Integer.html
java.lang Class Integer
The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method. Parameters: s - a string. Returns: the integer represented by the argument in decimal. Throws: NumberFormatException - if the string does not contain a parsable integer. public static Integer valueOf(String s, int radix) throws NumberFormatException ·
🌐
The Rust Programming Language
doc.rust-lang.org › book › ch03-02-data-types.html
Data Types - The Rust Programming Language
An integer is a number without a fractional component. We used one integer type in Chapter 2, the u32 type. This type declaration indicates that the value it’s associated with should be an unsigned integer (signed integer types start with i instead of u) that takes up 32 bits of space.