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 -
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
Joined: Jul 11, 2002
Posts: 72
posted
0
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
Joined: Jul 11, 2002
Posts: 72
posted
0
O.k. - You'll probably condemn me now [ September 11, 2002: Message edited by: Thomas Rochon ]
Try creating a custom class for your index, that resembles java.lang.Integer.
Thomas Rochon
Ranch Hand
Joined: Jul 11, 2002
Posts: 72
posted
0
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 -
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.