the book that im reading says
<< "this is the easy way to convert a numerical value to STRING"?"" + <number>
assuiming that the variable number is an integer.
is it what they called explicit conversion?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
the book that im reading says
<< "this is the easy way to convert a numerical value to STRING"?"" + <number>
assuiming that the variable number is an integer.
is it what they called explicit conversion?
Last edited by chronoz13; November 11th, 2009 at 05:17 AM.
No, that's an implicit conversion (technically, it's not a cast at all in this case, see the reason below). An explicit conversion is one you specifically tell Java to do:
int a = 5; String b = (String) a; // explicit
Note: because of the funny implementation of Strings in Java, this cast here will fail (the compiler will complain).
Reason: Java normally doesn't allow operator overloading. However, the + has been over-ridden for Strings to mean concatenation. The String concatenation method is able to take any primitive data type and convert it to a string equivalent value. However, because String is not a primitive data type, you cannot explicitly tell Java you want to cast an int to a String and vise versa.
Last edited by helloworld922; November 11th, 2009 at 10:22 AM.
oh sorry thats what im trying to imply, i just misinterpret the difference between "implicit" and " explicit" conversion..
yah yah, thats what i want to ask.. "implicit" haha,, ,
i thought this was "explicit"
[CODE] "" + number[\CODE]
so this is the "implicit"
anyway, so thats how the java manipulate strings, and tnx for the knowledge about "concatenating", every time i concatenate a primitive type i thougt that it still have value (i mean its data type) as it is when you declared it..
like the code above, i thought that the variable "number" is still the data type as when you declared it , but when you concatenate it with strings. it will become string too(and that is "implicit") hehe, thought it was "explicit" ,
i just understood it reversely..
concatenation doesn't really apply to primitives... It means "adding to the end of".
So:
is the same as"Hello" + " world"
"Hello".concat(" world");