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.


Re: Parsing 80 80

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).

Re: Parsing 80 80

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?

Re: Parsing 80 80

Erm maybe because 08765 isn't an integer?

Re: Parsing 80 80

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.

Re: Parsing 80 80

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?

Re: Parsing 80 80

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");
Re: Parsing 80 80

Thanks Ezzaral,

I did not even think of that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.