Integer.toString(int i) vs String.valueOf(int i) in Java

In String type we have several method valueOf static String valueOf(boolean b) static String valueOf(char c) static String valueOf(char[] data) static String valueOf(char[] data, int offset, int count) static String valueOf(double d) static String valueOf(float f) static String valueOf(int i) static String valueOf(long l) static String valueOf(Object obj) As we can see those method are … Read more

How to convert int to string in C++

C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string. #include <string> std::string s = std::to_string(42); is therefore the shortest way I can think of. You can even omit naming the type, using the auto keyword: auto s = std::to_string(42); … Read more

Differences between new Integer(123), Integer.valueOf(123) and just 123

new Integer(123) will create a new Object instance for each call. According to the javadoc, Integer.valueOf(123) has the difference it caches Objects… so you may (or may not) end up with the same Object if you call it more than once. For instance, the following code: public static void main(String[] args) { Integer a = … Read more

What is the differences between Int and Integer in Scala?

“What are the differences between Integer and Int?” Integer is just an alias for java.lang.Integer. Int is the Scala integer with the extra capabilities. Looking in Predef.scala you can see this the alias: /** @deprecated use <code>java.lang.Integer</code> instead */ @deprecated type Integer = java.lang.Integer However, there is an implicit conversion from Int to java.lang.Integer if … Read more