Beginner Java Question about Integer.parseInt() and casting

Posted by happysoul on Stack Overflow See other posts from Stack Overflow or by happysoul
Published on 2010-05-20T15:57:16Z Indexed on 2010/05/20 16:00 UTC
Read the original article Hit count: 260

Filed under:
|
|
|

so when casting like in the statement below :-

int randomNumber=(int) (Math.random()*5)

it causes the random no. generated to get converted into an int..

Also there's this method I just came across Integer.parseInt() which does the same !

i.e return an integer

Why two different ways to make a value an int ?

Also I made a search and it says parseInt() takes string as an argument.. So does this mean that parseInt() is ONLY to convert String into integer ?

What about this casting then (int) ?? Can we use this to convert a string to an int too ?

sorry if it sounds like a dumb question..I am just confused and trying to understand

Help ?

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner