Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

In this page you can find the example usage for java.util List toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:es.emergya.consultas.FlotaConsultas.java

public static Flota[] getAllHabilitadas() {
    List<Flota> res = new ArrayList<Flota>();
    // res.add(null);
    res.addAll(flotaHome.getAllHabilitadas());
    return res.toArray(new Flota[0]);
}

From source file:Main.java

/**
 * Remove the given element from the array.
 *
 * The check is done using String.equalsIgnoreCase() so it's case in-sensitive.
 *
 * @param array   the array/*  w w w  .  j av  a  2s .c  o  m*/
 * @param remove  the element to remove
 * @return a copy of the original array without the element.
 */
public static String[] removeElement(String[] array, String remove) {
    if (array == null)
        return array;
    if (remove == null)
        return array;

    List<String> elements = new ArrayList<>(array.length);
    for (String s : array) {
        if (s.equalsIgnoreCase(remove))
            continue;
        elements.add(s);
    }
    return elements.toArray(new String[0]);
}

From source file:es.emergya.consultas.FlotaConsultas.java

@Transactional
public static String[] getAllFilter() {
    List<String> res = new ArrayList<String>();
    res.add("");/* w  ww  .  j a  v  a  2 s  . com*/
    res.addAll(flotaHome.getAllNamesHabilitadas());
    return res.toArray(new String[0]);
}

From source file:com.activecq.experiments.activedecorator.mapdecorators.base.AbstractMapDecorator.java

protected static String[] toStringArray(final Object obj) {
    final List<String> list = new ArrayList<String>();
    for (final Object o : (Object[]) obj) {
        if (o instanceof String) {
            list.add((String) o);
        }/*from   ww  w.j a  v a 2s.c o  m*/
    }

    return list.toArray(new String[list.size()]);
}

From source file:com.diversityarrays.util.ClassPathExtender.java

public static void addDirectoryJarsToClassPath(Consumer<File> jarChecker, List<File> dirs, Log logger) {
    if (!dirs.isEmpty()) {
        addDirectoryJarsToClassPath(logger, jarChecker, dirs.toArray(new File[dirs.size()]));
    }/*  ww  w .j a v  a  2s  .c  o  m*/
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T[] toArray(List<T> items, Class<T> tClass) {
    if (items == null || items.size() == 0)
        return null;
    int size = items.size();
    try {/*from w  w w. j  av a  2  s  .  co m*/
        T[] array = (T[]) Array.newInstance(tClass, size);
        return items.toArray(array);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

protected static String[] split(final String str, final String delimiter) {
    if (str == null || str.trim().length() == 0) {
        return EMPTY_STRINGS;
    }/*from w ww  . j a  va2s.co m*/
    final List<String> list = new ArrayList<String>();
    final StringTokenizer st = new StringTokenizer(str, delimiter);
    while (st.hasMoreElements()) {
        list.add(st.nextToken());
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:illab.nabal.util.ParameterHelper.java

/**
 * Sort parameters using lexicographical byte value ordering.
 * //  w w w.j a v  a2s . c  o  m
 * @param params - list of parameters to sort
 * @return List<NameValuePair>
 */
public static List<NameValuePair> sortParams(List<NameValuePair> params) {
    NameValuePair[] sortedParams = params.toArray(new NameValuePair[params.size()]);
    Arrays.sort(sortedParams, paramComparator);
    params.clear();
    for (NameValuePair param : sortedParams) {
        params.add(param);
    }
    sortedParams = null;
    return params;
}

From source file:com.github.genium_framework.appium.support.command.CommandManager.java

/**
 * Execute a command on the operating system using Java's built-in Process
 * class//from   w  w  w . j  a  v a  2 s. c o m
 *
 * @param command A string array representation of the command to execute.
 * @param getOutput Whether or not to get the output/error streams of the
 * process you forked. This is helpful for debugging reasons.
 * @return A string representation of output/error streams of the process.
 */
public static String executeCommandUsingJavaRuntime(String[] command, boolean getOutput) {
    String output = "";

    try {
        Process p = Runtime.getRuntime().exec(command);

        // read the output from the command if requested by the user
        if (getOutput) {
            List<String> outErrStr = IOUtils.readLines(p.getInputStream());
            output = StringUtils.toString(outErrStr.toArray(new String[outErrStr.size()]), "\n");
        }
    } catch (Exception ex) {
        LOGGER.log(Level.SEVERE, "An exception was thrown while executing the command (" + command + ")", ex);
    }

    return output;
}

From source file:com.igormaznitsa.sciareto.preferences.FileHistoryManager.java

@Nonnull
private static String packToString(@Nonnull @MustNotContainNull final List<File> files) {
    return packToString(files.toArray(new File[files.size()]));
}