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

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.

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.