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:Main.java

public static Element[] getChildElementNodes(Node node) {
    if (node == null) {
        return null;
    }//from www .ja  v  a2 s  .co  m

    ArrayList<Element> elements = new ArrayList<>();
    NodeList nodeList = node.getChildNodes();
    if (nodeList != null && nodeList.getLength() > 0) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node item = nodeList.item(i);
            if (item != null && item.getNodeType() == Node.ELEMENT_NODE) {
                elements.add((Element) item);
            }
        }
    }
    return elements.toArray(new Element[elements.size()]);
}

From source file:io.github.jeremgamer.editor.panels.Panels.java

public static String[] getPanels() {
    ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < panelList.getModel().getSize(); i++) {
        list.add(panelList.getModel().getElementAt(i));
    }//from  w w  w.j a va 2  s  . c  om
    return list.toArray(new String[0]);
}

From source file:com.frostwire.gui.updates.PortableUpdater.java

private static String[] createMacOSXScriptCommand(File source, File dest) {
    ArrayList<String> command = new ArrayList<String>();
    command.add(new File(CommonUtils.getUserSettingsDir(), PORTABLE_UPDATER_SCRIPT_MACOSX).getAbsolutePath());
    command.add(source.getAbsolutePath());
    command.add(dest.getAbsolutePath());

    return command.toArray(new String[0]);
}

From source file:nl.ordina.bag.etl.util.Log4jUtils.java

public static String[] getLoggers() {
    ArrayList<String> result = new ArrayList<String>();
    for (@SuppressWarnings("unchecked")
    Enumeration<Logger> loggers = LogManager.getCurrentLoggers(); loggers.hasMoreElements();) {
        Logger logger = loggers.nextElement();
        result.add(logger.getName() + ": " + logger.getLevel());
    }/*from  w  ww.ja v  a 2  s.com*/
    Collections.sort(result);
    return result.toArray(new String[0]);
}

From source file:Main.java

private static IntBuffer[] generateMipmaps(int[] rgb, int width, int height, int mipmaps) {
    if (rgb == null) {
        return null;
    } else {/*from www .  j a v a  2 s.  c  o  m*/
        ArrayList mipmapData = new ArrayList();
        IntBuffer buffer = newIntBuffer(width * height * 4);
        buffer.put(rgb).position(0);
        int level = 0;

        while (true) {
            mipmapData.add(buffer);

            if (width <= 0 || height <= 0 || level >= mipmaps) {
                return (IntBuffer[]) mipmapData.toArray(new IntBuffer[mipmapData.size()]);
            }

            IntBuffer newBuffer = newIntBuffer(width * height);
            scaleHalf(buffer, width, height, newBuffer, 0);
            buffer = newBuffer;
            ++level;
            width >>= 1;
            height >>= 1;
        }
    }
}

From source file:LauncherBootstrap.java

/**
 * Convert a ":" separated list of URL file fragments into an array of URL
 * objects. Note that any all URL file fragments must conform to the format
 * required by the "file" parameter in the
 * {@link URL(String, String, String)} constructor.
 *
 * @param fileList the ":" delimited list of URL file fragments to be
 *  converted/* www . j  a va 2 s .  c o m*/
 * @return an array of URL objects
 * @throws MalformedURLException if the fileList parameter contains any
 *  malformed URLs
 */
private static URL[] fileListToURLs(String fileList) throws MalformedURLException {

    if (fileList == null || "".equals(fileList))
        return new URL[0];

    // Parse the path string
    ArrayList list = new ArrayList();
    StringTokenizer tokenizer = new StringTokenizer(fileList, ":");
    URL bootstrapURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.class.getName() + ".class");
    while (tokenizer.hasMoreTokens())
        list.add(new URL(bootstrapURL, tokenizer.nextToken()));

    return (URL[]) list.toArray(new URL[list.size()]);

}

From source file:Main.java

/**
 * Access all immediate child elements inside the given Element
 *
 * @param element the starting element, cannot be null.
 * @param elemName the name of the child element to look for, cannot be
 * null./* w w  w  .  ja  v  a  2s. c o  m*/
 * @return array of all immediate child element inside element, or
 * an array of size zero if no child elements are found.
 */
public static Element[] getChildElements(Element element, String elemName) {
    NodeList list = element.getChildNodes();
    int len = list.getLength();
    ArrayList<Node> array = new ArrayList<Node>(len);

    for (int i = 0; i < len; i++) {
        Node n = list.item(i);

        if (n.getNodeType() == Node.ELEMENT_NODE) {
            if (elemName.equals(n.getNodeName())) {
                array.add(n);
            }
        }
    }
    Element[] elems = new Element[array.size()];

    return (Element[]) array.toArray(elems);
}

From source file:com.house365.build.util.CsvUtil.java

/**
 * ?.//from   w  w w  .  j a  va2 s  .  c  om
 *
 * @param csvContent
 * @throws IOException
 */
public static void printlnCsv(ArrayList<LinkedHashMap<String, String>> csvContent) throws IOException {
    TableBuilder tb = new TableBuilder();
    ArrayList<String> headerNames = new ArrayList<>();
    LinkedHashMap<String, String> linkedHashMap = csvContent.get(0);
    for (Map.Entry<String, String> entry : linkedHashMap.entrySet()) {
        headerNames.add(entry.getKey());
    }
    String[] names = new String[headerNames.size()];
    headerNames.toArray(names);
    tb.addRow(names);
    for (HashMap<String, String> mapRecord : csvContent) {
        names = new String[headerNames.size()];
        mapRecord.values().toArray(names);
        tb.addRow(names);
    }
    tb.toString();
    BufferedReader reader = new BufferedReader(new StringReader(tb.toString()));
    String line = reader.readLine();
    System.out.println(AnsiColor.ANSI_YELLOW + line + AnsiColor.ANSI_RESET);
    for (line = reader.readLine(); line != null; line = reader.readLine()) {
        System.out.println(AnsiColor.ANSI_GREEN + line + AnsiColor.ANSI_RESET);
    }
}

From source file:com.scaniatv.LangFileUpdater.java

/**
 * Method that gets a list of all lang files.
 * //from   w  w w  .  ja v  a  2 s .  com
 * @return 
 */
public static String[] getLangFiles() {
    Collection<File> files = FileUtils.listFiles(new File(DEFAULT_LANG_ROOT), TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    ArrayList<String> fileNames = new ArrayList<>();

    String sep = File.separator;

    files.forEach((File file) -> {
        fileNames.add(file.getPath().replace("." + sep + "scripts" + sep + "lang" + sep + "english" + sep, ""));
    });

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

From source file:Main.java

public static Node[] getChildNodes(final Node node, final String attributeName, final String value) {
    final ArrayList nodeList = new ArrayList();
    final NodeList childs = node.getChildNodes();
    String readValue = null;/*from   w  w w. j a v a  2s  .  com*/
    for (int i = 0; i < childs.getLength(); i++) {
        readValue = getAttribute(childs.item(i), attributeName);
        if (value.equals(readValue)) {
            nodeList.add(childs.item(i));
        }
    } //next child node
    final Node[] result = new Node[nodeList.size()];
    nodeList.toArray(result);
    return result;
}