File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cast from string to integer

 
alona ariel
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str = "100";

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

System.out.println(i + " / " + bigInt);
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseInt is preferred if you don't need an Integer but an int, since it will not create any Integer object.
 
alona ariel
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you a lot.
but how i can make the opposite casting from integer to string
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic