arraylist - Efficient way to split a number in Java -
this question has answer here:
- how separate digits of int number? 21 answers
i'm struggling finding efficient way split digits of number list.
for example, number:
23464646237
and
arraylist <integer> vector;
i want insert in each position of array, digit number, therefore obtaining following output:
vector = {2,3,4,6,4,6,4,6,2,3,7}
how can in clean , efficient way in java ?
thanks in advance
the parseint
not needed,
for(int = 0; < numberasstring.length(); i++) vector.add((int)numberasstring.charat(i) - 48);
this retrieve ascii value of number @ position, subtract 48 value of 0 in table.
number -127 127 cached believe efficient method (note i'm not 100% sure). anyway, tried give way saving parseint
call asked most efficient.
Comments
Post a Comment