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:hsyndicate.utils.IPUtils.java

public static String selectLocalIPAddress(List<String> addresses) {
    return selectLocalIPAddress(addresses.toArray(new String[0]));
}

From source file:com.jroossien.boxx.util.Utils.java

/**
 * Fixes the specified list of command arguments.
 * It will combine arguments that are quoted with spaces.
 * For example the following string: 'Hello there "you''re awesome"!'
 * Would result in 0:Hello 1:there 2:You''re awesome 3:!
 *
 * @param args The list of arguments to fix.
 * @return The modified array with arguments.
 *//*ww w .ja  v  a  2s  .  c  om*/
public static String[] fixCommandArgs(String[] args) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        builder.append(args[i]);
        if (i + 1 < args.length) {
            builder.append(" ");
        }
    }

    List<String> newArgList = Str.splitQuotes(builder.toString());
    return newArgList.toArray(new String[newArgList.size()]);
}

From source file:Main.java

/**
 * @param domainsAtt//from  ww w.j  a v  a 2  s  .co  m
 * @return
 */
private static String[] getPropsAtts(String domainsAtt) {
    List<String> propsAtts = new ArrayList<String>();
    String[] result = new String[propsAtts.size()];
    propsAtts.addAll(BASE_PROPS_ATTS);
    if (domainsAtt == null)
        return propsAtts.toArray(result);
    char c;
    int p = 0;
    while (p < domainsAtt.length()) {
        c = domainsAtt.charAt(p);
        switch (c) {
        case ' ':
        case '\t':
            p++;
            break;
        case '(':
            p = parseParens(domainsAtt, ++p);
            break;
        case 'a':
            p = parsePropsDomain(domainsAtt, ++p, propsAtts);
            break;
        default:
            throw new RuntimeException("Unexpected character \"" + c + "\" at position " + p + 1
                    + " in domains attribute value \"" + domainsAtt + "\"" + ". Expected space, '(', or 'a'.");
        }
    }
    result = new String[propsAtts.size()];
    return propsAtts.toArray(result);
}

From source file:com.starit.diamond.utils.AppNameUtils.java

public static String[] getAllAppNames(String[] excludes) {
    File classpath = getClasspath();
    File deployDir = classpath.getParentFile();
    List<String> appNames = new LinkedList<String>();
    for (String suffix : SUFFIXS) {
        File[] files = listFiles(deployDir, suffix, excludes);
        addFilesToAppNames(files, appNames, suffix);
    }/*from  w w  w. j  av  a 2s. c  o  m*/
    return appNames.toArray(new String[appNames.size()]);
}

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

@SuppressWarnings({ "unchecked" })
public static SortedMap<String, String[]> headersToMap(final HttpServletRequest request) {
    return namedAttributesToMap(request.getHeaderNames(), new AttributeAccessor<String[]>() {
        @SuppressWarnings({ "unchecked" })
        public String[] getAttribute(String headerName) {
            Enumeration<String> values = request.getHeaders(headerName);
            List<String> valList = new ArrayList<String>();
            while (values.hasMoreElements()) {
                valList.add(values.nextElement());
            }//from w  w  w .j  a  va  2  s.  co m
            return valList.toArray(new String[valList.size()]);
        }
    });
}

From source file:ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.java

private static URL[] toUrls(List<File> ivyEngineClassPathFiles) throws MalformedURLException {
    List<URL> classPathUrls = new ArrayList<>();
    for (File file : ivyEngineClassPathFiles) {
        classPathUrls.add(new URL(file.toURI().toASCIIString()));
    }//  www.  j  av a 2  s.  c om
    return classPathUrls.toArray(new URL[classPathUrls.size()]);
}

From source file:Main.java

public static Node[] getChildNodes(Node node, short type) {
    NodeList children = node.getChildNodes();
    if (children == null) {
        return new Node[0];
    }/*ww w .ja v  a 2  s. co m*/
    int n = children.getLength();
    List<Node> elnodelist = new ArrayList<Node>(n);
    for (int i = 0; i < n; ++i) {
        Node childnode = children.item(i);
        if (childnode.getNodeType() == type) {
            elnodelist.add(childnode);
        }
    }
    Node[] empty = {};
    return elnodelist.toArray(empty);
}

From source file:adalid.commons.velocity.VelocityEngineer.java

private static void setFileResourceLoaderPath(List<String> list) {
    fileResourceLoaderPathArray = list.toArray(new String[0]);
    logger.trace(FILE_RESOURCE_LOADER_PATH + " = ");
    for (String dir : fileResourceLoaderPathArray) {
        logger.trace("\t" + dir);
    }/*from   w  ww  . ja v a 2s . c o  m*/
}

From source file:com.galenframework.speclang2.pagespec.ForLoop.java

private static String[] readSequenceFromPageObjects(String sequenceStatement, PageSpecHandler pageSpecHandler) {
    List<String> matchingObjects = pageSpecHandler.findAllObjectsMatchingStrictStatements(sequenceStatement);
    return matchingObjects.toArray(new String[matchingObjects.size()]);
}

From source file:Main.java

/**
 * Get the Element children of an element as an array.
 * @param element/*from   w  ww  .j av  a2s.co  m*/
 * @return non-<code>null</code> array 
 */
public static Element[] getChildElements(Element element) {
    NodeList childNodes = element.getChildNodes();
    List<Element> kids = new ArrayList<Element>();
    Node node = childNodes.item(0);
    while (node != null) {
        if (node instanceof Element) {
            kids.add((Element) node);
        }
        node = node.getNextSibling();
    }
    return (Element[]) kids.toArray(new Element[kids.size()]);
}