• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

how to turn a one-digit into a two-digit one

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there !
It's not that dramatic, but I asked myselfe
if there exists a method which turns my
one-digit int (e.g. 1) to a two-digit one (in this case 01) ?
I could write a method by my own.
But I'd like to know if there is something
like that already done ?
That's all
Thanx & bye !
- Thomas -
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of datatype will hold '01'? Well, anything besides char datatypes (String, Object, etc)??
Just curious on how you plan or storing that value or what datatype you are going to store it in.
 
Thomas Rochon
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregg !
I wanna read some Strings out of an ArrayList
and give every String an index from 01 to 15 (or something). That index should be stored into a String.
My code looks something like that:
for (int i=0; i < names.size(); i++) {
Element name = (Element)names.get(i);
out.println(i+". "+name.getFirstName());
}
The output should look like this:
01. Peter
02. Paula
...
10. Jenny
a.s.o.
Problem is, that i is an one-digit int.
O.k. ?
 
Thomas Rochon
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O.k. - You'll probably condemn me now
[ September 11, 2002: Message edited by: Thomas Rochon ]
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try creating a custom class for your index, that resembles java.lang.Integer.
 
Thomas Rochon
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anthony !
Thanx for your reply. I'll try to do so.
I hoped there would be a package java.util.something that contains a method
to do that job for me
Thanx !
- Thomas -
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at java.text.NumberFormat. I think you can get what you want through that.
Be careful about trying to save your integer with the prepended '0'. 01 is not the same to Java as 1. 1 is in base 10. 01 is in octal (base eight). It doesn't really matter for 0-7, but 08 and 09 don't exist, and you could have problems.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic