0

Here's an easy one for you experts :P

What is casting and parsing? How exactly are they different?

After explaining, could anyone possibly tell me how to cast/parse the various types from and to each other? (the types being: int, double, char and String)

Also, in which situations would I end up using either one of these?

Thanks :D

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Mattox
0

Parsing - changes a String into a primitive data type(may be other uses)
Casting - changes from one primitive data type to another, can also be used to cast objects.

Use, if you have a string and need to convert it into a primitive type us Parsing
i.e.

String s = "23";
int i = Integer.parseInt(s);

If you have a primitive type and need to convert it to another primitive type, use casting.

To take a primitive type to a String you have to use a Wrapper class. A Wrapper class allows you to make an object out of a primitive type.

String s = Integer.toString(8);//toString() is a method that most(if not all) objects have

As far as listing a bunch of conversion types, you can do a Google search as needed.

This topic has been dead for over six months. 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.