Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <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:com.amalto.workbench.compare.Utilities.java

public static IResource[] getResources(ISelection selection) {
    ArrayList tmp = internalGetResources(selection, IResource.class);
    return (IResource[]) tmp.toArray(new IResource[tmp.size()]);
}

From source file:Main.java

public static Node[] findNodesByTagName(Node parentNode, String tagName) {
    ArrayList<Node> nodes = new ArrayList<Node>();

    for (int i = 0; i < parentNode.getChildNodes().getLength(); i++) {
        Node node = parentNode.getChildNodes().item(i);

        if (node.getNodeName().equals(tagName))
            nodes.add(node);/*from  ww  w . j  av a2 s.com*/

        if (node.hasChildNodes()) {
            Node[] foundChildNodes = findNodesByTagName(node, tagName);
            for (int j = 0; j < foundChildNodes.length; j++)
                nodes.add(foundChildNodes[j]);

        }
    }

    Node[] returnNodes = new Node[nodes.size()];
    return nodes.toArray(returnNodes);
}

From source file:jef.tools.chinese.CFJUtil.java

private static Mapping[] loadMapping(String fileName, int size) {
    String line = null;//ww  w. ja v a 2s .co  m
    BufferedReader br = null;
    int num = 0;
    try {
        br = IOUtils.getReader(CFJUtil.class, fileName, "UTF-8");
        ArrayList<Mapping> list = new ArrayList<Mapping>(size);
        while ((line = br.readLine()) != null) {
            if (line.startsWith("#") || StringUtils.isBlank(line)) {
                continue;
            }
            char fChar = line.charAt(0);
            char jChar = line.charAt(2);
            list.add(new Mapping(jChar, fChar));
            num++;
        }
        return list.toArray(new Mapping[list.size()]);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        IOUtils.closeQuietly(br);
    }
}

From source file:de.kapsi.net.daap.DaapHeaderConstructor.java

/**
 * Creates a new Authentication Header/*from   w  w  w  . j  av a  2s. co  m*/
 *
 * @param request
 * @return
 */
public static byte[] createAuthHeader(DaapRequest request) {

    try {

        DaapConnection connection = request.getConnection();
        String serverName = connection.getServer().getConfig().getServerName();

        ArrayList headers = new ArrayList();

        headers.add(new Header("Date", DaapUtil.now()));
        headers.add(new Header("DAAP-Server", serverName));
        headers.add(new Header("Content-Type", "text/html"));
        headers.add(new Header("Content-Length", "0"));
        //                headers.add(new Header("WWW-Authenticate", "Basic-realm=\"daap\""));

        return toByteArray(HTTP_AUTH, (Header[]) headers.toArray(new Header[0]));

    } catch (UnsupportedEncodingException err) {
        // Should never happen
        throw new RuntimeException(err);

    } catch (IOException err) {
        // Should never happen
        throw new RuntimeException(err);
    }
}

From source file:net.mindengine.galen.runner.GalenArguments.java

private static String[] processSystemProperties(String[] args) {
    ArrayList<String> list = new ArrayList<String>();

    for (String arg : args) {
        if (arg.startsWith("-D")) {
            setSystemProperty(arg);//ww  w  . ja  va2 s. c  o m
        } else {
            list.add(arg);
        }
    }
    return list.toArray(new String[] {});
}

From source file:com.ikon.module.jcr.stuff.JCRUtils.java

/**
 * /* www. j ava  2s.  co  m*/
 */
public static String[] value2String(Value[] values)
        throws ValueFormatException, IllegalStateException, javax.jcr.RepositoryException {
    ArrayList<String> list = new ArrayList<String>();

    for (int i = 0; i < values.length; i++) {
        list.add(values[i].getString());
    }

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

From source file:com.yamin.kk.vlc.Util.java

public static String[] getMediaDirectories() {
    ArrayList<String> list = new ArrayList<String>();
    list.addAll(Arrays.asList(Util.getStorageDirectories()));
    list.addAll(Arrays.asList(Util.getCustomDirectories()));
    return list.toArray(new String[list.size()]);
}

From source file:com.opendoorlogistics.speedregions.excelshp.app.FileBrowserPanel.java

public static JComponent[] createBrowserComponents(String label, String initialFilename,
        final Consumer<String> filenameChangeListener, final boolean directoriesOnly,
        final String browserApproveButtonText, final FileFilter... fileFilters) {
    ArrayList<JComponent> ret = new ArrayList<JComponent>();
    if (label != null) {
        ret.add(new JLabel(label));
    }//from  ww  w .j ava 2s  .c  om
    JTextField textField = createTextField(initialFilename, filenameChangeListener);
    ret.add(textField);
    textField.setPreferredSize(new Dimension(200, 28));

    ret.add(createBrowseButton(directoriesOnly, browserApproveButtonText, textField, fileFilters));
    return ret.toArray(new JComponent[ret.size()]);
}

From source file:JarUtils.java

/**
 * Add jar contents to the deployment archive under the given prefix
 *///from ww w  . j av  a2  s  .  c om
public static String[] addJar(JarOutputStream outputStream, String prefix, File jar) throws IOException {

    ArrayList tmp = new ArrayList();
    FileInputStream fis = new FileInputStream(jar);
    JarInputStream jis = new JarInputStream(fis);
    JarEntry entry = jis.getNextJarEntry();
    while (entry != null) {
        if (entry.isDirectory() == false) {
            String entryName = prefix + entry.getName();
            tmp.add(entryName);
            addJarEntry(outputStream, entryName, jis);
        }
        entry = jis.getNextJarEntry();
    }
    jis.close();
    String[] names = new String[tmp.size()];
    tmp.toArray(names);
    return names;
}

From source file:com.wallerlab.compcellscope.Image_Gallery.java

public static File[] removeElements(File[] input, String deleteMe) {
    ArrayList<File> result = new ArrayList<File>();
    Log.d("Image_Gallery", "Got here: " + input.length);
    for (File item : input)
        if (!item.toString().contains(deleteMe))
            result.add(item);/*  w  w w .j  a  v  a2 s.  c om*/

    Log.d("Image_Gallery", "Got here: " + result.size());

    return result.toArray(new File[result.size()]);
}