Java ListIterator Usage numberToDigits(int num)

Here you can find the source of numberToDigits(int num)

Description

number To Digits

License

Open Source License

Declaration

public static int[] numberToDigits(int num) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;
import java.util.ListIterator;

public class Main {
    public static int[] numberToDigits(int num) {
        if (num < 0) {
            throw new IllegalArgumentException("num should not be negative");
        }/*from w w w. j  av  a  2 s .co  m*/

        final int RADIX = 10;

        List<Integer> list = new ArrayList<Integer>();
        while (num > 0) {
            list.add(num % RADIX);
            num /= RADIX;
        }

        int[] ret = new int[list.size()];
        ListIterator<Integer> itr = list.listIterator();
        while (itr.hasNext()) {
            int idx = itr.nextIndex();
            ret[idx] = itr.next();
        }

        return ret;
    }
}

Related

  1. listEquals(List left, List right)
  2. listHasIdentContent(List list_1, List list_2)
  3. listToStringArray(java.util.List list)
  4. makeSortFieldFallbackExpr(List fieldNames)
  5. normalizeVersion(String version, int length)
  6. overlap(List> lists, int before, int after)
  7. parsePath(String sPath)
  8. partialSort(List list, int numTop, Comparator c)
  9. peekNext(ListIterator it)