This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Casting strings Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Casting strings" Watch "Casting strings" New topic
Author

Casting strings

Yasmeen G
Greenhorn

Joined: Oct 19, 2000
Posts: 2
I'm a beginner and I need help!
I would like to change a string into an integer. I've tried
int number = (int) j;//j is the string here.
I've tried other things and they don't work either. Surfing the web hasn't been helping me either.
Hope someone can help!
thanks.
Richard Mack
Greenhorn

Joined: Oct 19, 2000
Posts: 3
In Java, Strings are object references. It is illegal to cast/convert an object reference (J) to a primative (number).
What are you trying to accomplish this for?
Siobhan Murphy
Ranch Hand

Joined: Oct 19, 2000
Posts: 72
Try the following:
String j = "2024";
int i = Integer.parseInt(j);
Yasmeen G
Greenhorn

Joined: Oct 19, 2000
Posts: 2
Thanks for the help! It worked. I was just constructing a simple program.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Casting strings
 
Similar Threads
RMI server client
Cast object[][] into strings
Doubt with overloaded super constructor
How to print this pattern using nested for loops
why won't charAt work?