Java List to String toStringList(final double[] array)

Here you can find the source of toStringList(final double[] array)

Description

to String List

License

Open Source License

Declaration

public static List<String> toStringList(final double[] array) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> toStringList(final double[] array) {
        List<String> list = new ArrayList<String>(array.length);
        for (int i = 0; i < array.length; i++) {
            list.add(String.valueOf(array[i]));
        }/*from ww w. ja v  a 2  s.  c o m*/
        return list;
    }

    public static List<String> toStringList(final int[] array) {
        List<String> list = new ArrayList<String>(array.length);
        for (int i = 0; i < array.length; i++) {
            list.add(String.valueOf(array[i]));
        }
        return list;
    }

    public static <E> List<String> toStringList(final E[] array) {
        List<String> stringList = null;
        if (array != null) {
            stringList = new ArrayList<String>(array.length);
            for (E e : array) {
                if (e != null) {
                    stringList.add(e.toString());
                } else {
                    stringList.add(null);
                }
            }
        }
        return stringList;
    }

    public static <E> String toString(final int[] list) {
        return toString(list, "\t");
    }

    public static <E> String toString(final int[] list, String separator) {
        StringBuilder sb = new StringBuilder();
        if (list != null && list.length > 0) {
            for (int i = 0; i < list.length - 1; i++) {
                sb.append(list[i]).append(separator);
            }
            sb.append(list[list.length - 1]);
        }
        return sb.toString();
    }

    public static <E> String toString(final double[] list) {
        return toString(list, "\t");
    }

    public static <E> String toString(final double[] list, String separator) {
        StringBuilder sb = new StringBuilder();
        if (list != null && list.length > 0) {
            for (int i = 0; i < list.length - 1; i++) {
                sb.append(list[i]).append(separator);
            }
            sb.append(list[list.length - 1]);
        }
        return sb.toString();
    }

    public static <E> String toString(final E[] list) {
        return toString(list, "\t");
    }

    public static <E> String toString(final E[] list, String separator) {
        StringBuilder sb = new StringBuilder();
        if (list != null && list.length > 0) {
            for (int i = 0; i < list.length - 1; i++) {
                if (list[i] != null) {
                    sb.append(list[i].toString()).append(separator);
                } else {
                    sb.append("null");
                }
            }
            if (list[list.length - 1] != null) {
                sb.append(list[list.length - 1].toString());
            } else {
                sb.append("null");
            }
        }
        return sb.toString();
    }
}

Related

  1. toString(List list)
  2. toStringClassList(List list)
  3. toStringDelimited(final Iterable list, final String delimiter)
  4. toStringItem(List> itemMapList, String subjectName)
  5. toStringList(Collection strings, String separator)
  6. toStringList(final E[] array)
  7. toStringList(final List list)
  8. toStringList(final String tags)
  9. toStringList(HashSet V)

  10. HOME | Copyright © www.java2s.com 2016