This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes converts integer into string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converts integer into string" Watch "converts integer into string" New topic
Author

converts integer into string

Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
how do i convert an integer into a string? i want to be able to get the length of the number, such as 34567 being 5 characters long. but, when i try this i get a compiler error saying that int was detected. here is my code:

[This message has been edited by Thomas Whalen (edited November 25, 2001).]


if you don't know, then ask. if you do know, then share. love is knowledge.
Ben Carlson
Greenhorn

Joined: Nov 25, 2001
Posts: 3
this is a quick fix... I haven't found (then again I haven't looked) another way of doing this...
String str = "" + integer;
To convert a string to an integer, use this:
int i = Integer.parseInt(String);
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
okay, I got it. here is the code to get the length of an integer:


Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
In Java, convention dictates that Class names begin with upper-case, and variable/method names begin with lower case.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
oops, forgot about that ...what about variable names containing more than one word? which of the below styles is best for naming multi-word varibles?
variableFOO
variable_FOO
variable_foo
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Thomas Whalen:
What about variable names containing more than one word? which of the below styles is best for naming multi-word varibles?

variableFOO
variable_FOO
variable_foo


None of the above. Try

variableFoo
moreThanOneWordVariable

Only if you're using an acronym
theOneAndOnlyHTTPMethod()
myURLFinder

Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Back to the original question - to convert any variable (either primitive or object) to a String, use String.valueOf: - Peter
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
thank you peter. much easier than using Integer.toString() method, THEN getting length of string.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converts integer into string
 
Similar Threads
Changing decimal to octale (and etc.)
cast int to Number
Varargs overriding
difference of int and INTEGER
parsing standard input