Java Array to String toStringArray(int[] nums)

Here you can find the source of toStringArray(int[] nums)

Description

to String Array

License

Apache License

Declaration

public static String[] toStringArray(int[] nums) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {

    public static String[] toStringArray(int[] nums) {
        if (nums == null) {
            return null;
        }/* w w  w .j av a2  s .  c  o m*/

        String[] fields = new String[nums.length];
        int index = 0;
        for (Integer num : nums) {
            fields[index] = Integer.toString(num);
            index++;
        }
        return fields;
    }

    public static String[] toStringArray(List<Integer> list) {
        if (isEmpty(list)) {
            return null;
        }
        String[] fields = new String[list.size()];
        int index = 0;
        for (Integer num : list) {
            fields[index] = Integer.toString(num);
            index++;
        }
        return fields;
    }

    public static boolean isEmpty(List<?> list) {
        if (list == null || list.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    public static int size(Object[] list) {
        if (list == null) {
            return 0;
        } else {
            return list.length;
        }
    }

    public static int size(long[] list) {
        if (list == null) {
            return 0;
        } else {
            return list.length;
        }
    }

    public static int size(List<?> list) {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }
}

Related

  1. toString(T[] array)
  2. toString(T[] array, String prefix, String sep, String suffix)
  3. toStringArray(Collection strings)
  4. toStringArray(Dictionary props, String key, String[] defaultArray)
  5. toStringArray(final E[] array)
  6. toStringArray(Object value)
  7. toStringKeyValuePairs(Object[] keys, Object[] values, int size, StringBuilder dstOptional)
  8. toStrings(byte[] bytes)