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

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.

commented: thanks.. +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.