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

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

Description

to String List

License

Open Source License

Declaration

@Deprecated
    public static <E> List<String> toStringList(final E[] array) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <E> List<String> toStringList(final List<E> list) {
        List<String> stringList = null;
        if (list != null) {
            stringList = new ArrayList<String>(list.size());
            for (E e : list) {
                if (e != null) {
                    stringList.add(e.toString());
                } else {
                    stringList.add(null);
                }//  w  ww  . j  a va  2  s.  c o  m
            }
        }
        return stringList;
    }

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

    @Deprecated
    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]));
        }
        return list;
    }

    @Deprecated
    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> String toString(final List<E> list) {
        return toString(list, "\t");
    }

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

Related

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

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