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 OverflowVideos
Integer.valueOf() and parseint()
Java valueOf() method, and such
Whats the point of using Integer.valueOf(scanner.nextLine()); ?
Difference between 'new Integer(value)' and ...
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.
Yes, this is equivalent to:
size = Integer.parseInt(line, 16);
Indeed, looking at the implementation, the existing code is actually implemented as effectively:
size = Integer.valueOf(Integer.parseInt(line, 16)).intValue();
which is clearly pointless.
The assignment to -1 in the previous line is pointless, by the way. It would only be relevant if you could still read the value if an exception were thrown by Integer.parseInt, but as the scope of size is the same block as the call to Integer.valueof, it won't be in scope after an exception anyway.
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?
Hello friends, I wanted to ask anyone who knew Java what the deal with the valueOf() method was. You see, I was under the assumption that it set it's output to whatever variable it was being associated with, seems simple enough. I tried to use this to get around not being able to convert integers to Strings and vice versa. However, it still displayed a syntax error that I cannot, and it's really getting on my nerves because I need to convert a string to an integer for a homework assignment and nothing I've tried is working. Thanks for your time, and for reading.
I genuinely don't know what the point of using anything other than Scanner variableName = scanner.nextLine(), if they both give the same output
example.