Hello All,

I am trying to parse an ArrayList of Strings into an ArrayList of integers. Does anyone have any opinions on how this should be done?

I can parse one element, but parsing the entire string where I am having problems. Any suggestions would be great.


Show an example (of the input and the desired output), as well as the code you have for doing it (at least what you have so far).

Well, I figured out how to parse, however, when i print out the Arrays, it does not print out the first zero.



it prints 8765

any suggestions on how to fix this?

Erm maybe because 08765 isn't an integer?

Exactly. If you really need leading zeros then you have to create that String representation yourself - which will undo the whole point of converting in the first place.

well, I have two arrays of Strings that need to be compared to increment the range of integers up to the integer in the second array. So, I parsed the Strings into Integers in order to compare them. So am I now to parse back to Strings in order to get the initial 0?

Only if they must be stored as strings. If you provided sample input and output and indicated what you need to do with the output, it would be helpful in answering the question.

If it is only a matter of displaying them with leading zeros to the user then there are several formatting methods availble for that (i.e. String. format , Formatter , DecimalFormat )

int x = 123;
         int y = 23;
         DecimalFormat df = new DecimalFormat("0000");
This question has already been answered. Start a new discussion instead.