Java Boolean From toBooleanArray(final E[] array)

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

Description

to Boolean Array

License

Open Source License

Declaration

public static <E> boolean[] toBooleanArray(final E[] array) 

Method Source Code

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

public class Main {
    public static <E> boolean[] toBooleanArray(final E[] array) {
        boolean[] stringList = null;
        if (array != null) {
            stringList = new boolean[array.length];
            for (int i = 0; i < array.length; i++) {
                if (array[i] != null) {
                    try {
                        stringList[i] = "true".equalsIgnoreCase(array[i].toString().trim())
                                || "1".equals(array[i].toString().trim());
                    } catch (NumberFormatException nfe) {
                        stringList[i] = false;
                    }/*  ww  w . j a va 2s.com*/
                } else {
                    stringList[i] = false;
                }
            }
        }
        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. toBooleanA(byte[] data)
  2. toBooleanArray(byte a, boolean[] buf)
  3. toBooleanArray(byte[] array)
  4. toBooleanArray(byte[] byteArray)
  5. toBooleanArray(byte[] data)
  6. toBooleanArray(final Object[] array)
  7. toBooleanArray(int[] intArray, int n)
  8. toBooleanArray(Object[] vs)
  9. toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)