0

i have one question.
I understand the type conversion in java.But i dont know where to use which conversion.
Below i have given one example,but i don't which is used where?

String s=”27”;
int i=Integer.parseInt(s);
System.out.println(i);
///////////////////////////////////

String s=”27”;
int i=(int)s;
System.out.println(i);

Although both are doing the same thing,but where to use which conversion?

Thanks

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by JamesCherrill
2

In this case the answer is trivial. Version 1 works, and version 2 doesn't. Your compiler will tell you the same thing. You can't cast from a String to an int. Check out the Java Language Spec section on casting to see the rules on what you can or cannot convert by a cast.

Votes + Comments
thanks..
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.