File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes cast from string to integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cast from string to integer" Watch "cast from string to integer" New topic
Author

cast from string to integer

alona ariel
Ranch Hand

Joined: Sep 09, 2008
Posts: 36
I receive type parameter in string and want to change it to integer how I can do it
String command1=st.nextToken();
Roland Maurer
Greenhorn

Joined: Nov 23, 2008
Posts: 17
String str = "100";

int i = Integer.parseInt(str);
// or
Integer bigInt = new Integer(str);

System.out.println(i + " / " + bigInt);
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

parseInt is preferred if you don't need an Integer but an int, since it will not create any Integer object.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
alona ariel
Ranch Hand

Joined: Sep 09, 2008
Posts: 36
thank you a lot.
but how i can make the opposite casting from integer to string
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by alona ariel:
...but how i can make the opposite casting from integer to string

Hint: When Roland told you the Integer class has a method to parse a String as an int, that should have prompted you to look at the API documentation for the Integer class. Maybe it has a similar method for creating a String from an int.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
 
subject: cast from string to integer