Example usage for java.util LinkedList toArray

List of usage examples for java.util LinkedList toArray

Introduction

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

Prototype

public Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    Object[] objArray = lList.toArray();

    for (Object obj : objArray) {
        System.out.println(obj);/* w ww. ja  va  2s. c o m*/
    }
}

From source file:Main.java

public static void main(String args[]) {
    LinkedList<String> ll = new LinkedList<String>();

    ll.add("A");/* w w  w  .  ja va 2s  .  com*/
    ll.add("java2s.com");
    ll.add("B");
    ll.add("C");
    ll.add("java2s.com");

    Object[] objs = ll.toArray();
    System.out.println(Arrays.toString(objs));

    String[] strs = ll.toArray(new String[ll.size()]);
    System.out.println(Arrays.toString(strs));
}

From source file:Main.java

public static void main(String[] args) {

    LinkedList<String> list = new LinkedList<String>();

    list.add("Hello");
    list.add("from java2s.com");
    list.add("java tutorial");

    // print the list
    System.out.println("LinkedList:" + list);

    // create an array and copy the list to it
    Object[] array = list.toArray();

    System.out.println(Arrays.toString(array));
}

From source file:com.scit.sling.test.MockResourceFactory.java

private static ResourceNode parseJsonObject(ResourceNode context, JsonParser jp)
        throws JsonParseException, IOException {
    JsonToken token;/*from   w w  w  .j  av  a2 s.  co m*/
    String fieldname = "";
    while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
        switch (token) {
        case START_OBJECT:
            ResourceNode child = new ResourceNode(context, fieldname);
            context.addChild(child);
            parseJsonObject(child, jp);
            break;
        case FIELD_NAME:
            fieldname = jp.getCurrentName();
            break;
        case START_ARRAY:
            LinkedList<Object> array = new LinkedList<Object>();
            while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
                array.add(parseValue(token, jp));
            }
            context.addProperty(fieldname, array.toArray());
            break;
        default:
            if (token.isScalarValue()) {
                context.addProperty(fieldname, parseValue(token, jp));
            }
            // log.warnd ???
        }
    }
    return context;
}

From source file:vmware.au.se.sqlfireweb.controller.HistoryController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/sqlfireweb/login");
        return null;
    }/*from  w w w .j  a  va2 s .  c o m*/

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

    // This will resolve to /WEB-INF/jsp/history.jsp
    return "history";
}

From source file:pivotal.au.se.gemfirexdweb.controller.HistoryController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from w w  w .j  a  va 2 s  . c  om*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

    // This will resolve to /WEB-INF/jsp/history.jsp
    return "history";
}

From source file:org.polymap.p4.atlas.ui.SearchContentProvider.java

public TreePath treePathOf(Object elm) {
    LinkedList result = new LinkedList();
    for (Object current = elm; current != null; current = getParent(current)) {
        if (current != input) {
            result.addFirst(current);//  www.jav  a2 s  .  co  m
        }
    }
    return new TreePath(result.toArray());
}

From source file:com.newlandframework.avatarmq.core.SendMessageCache.java

public void parallelDispatch(LinkedList<MessageDispatchTask> list) {
    List<Callable<Void>> tasks = new ArrayList<Callable<Void>>();
    int startPosition = 0;
    Pair<Integer, Integer> pair = calculateBlocks(list.size(), list.size());
    int numberOfThreads = pair.getRight();
    int blocks = pair.getLeft();

    for (int i = 0; i < numberOfThreads; i++) {
        MessageDispatchTask[] task = new MessageDispatchTask[blocks];
        phaser.register();/*  w w  w.ja  v  a2  s.c om*/
        System.arraycopy(list.toArray(), startPosition, task, 0, blocks);
        tasks.add(new SendMessageTask(phaser, task));
        startPosition += blocks;
    }

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
    for (Callable<Void> element : tasks) {
        executor.submit(element);
    }
}

From source file:com.newlandframework.avatarmq.core.AckMessageCache.java

public void parallelDispatch(LinkedList<String> list) {
    List<Callable<Long>> tasks = new ArrayList<Callable<Long>>();
    List<Future<Long>> futureList = new ArrayList<Future<Long>>();
    int startPosition = 0;
    Pair<Integer, Integer> pair = calculateBlocks(list.size(), list.size());
    int numberOfThreads = pair.getRight();
    int blocks = pair.getLeft();

    barrier = new CyclicBarrier(numberOfThreads);

    for (int i = 0; i < numberOfThreads; i++) {
        String[] task = new String[blocks];
        System.arraycopy(list.toArray(), startPosition, task, 0, blocks);
        tasks.add(new AckMessageTask(barrier, task));
        startPosition += blocks;//from w w w. j  a v a2  s.co  m
    }

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
    try {
        futureList = executor.invokeAll(tasks);
    } catch (InterruptedException ex) {
        Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (Future<Long> longFuture : futureList) {
        try {
            succTaskCount += longFuture.get();
        } catch (InterruptedException ex) {
            Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ExecutionException ex) {
            Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.apache.cocoon.woody.binding.MultiValueJXPathBinding.java

public void doLoad(Widget frmModel, JXPathContext jctx) throws BindingException {
    Widget widget = frmModel.getWidget(this.multiValueId);
    if (widget == null) {
        throw new BindingException("The widget with the ID [" + this.multiValueId
                + "] referenced in the binding does not exist in the form definition.");
    }/*w  ww  .j av a2  s  .c om*/

    // Move to multi value context
    Pointer ptr = jctx.getPointer(this.multiValuePath);
    if (ptr.getNode() != null) {
        // There are some nodes to load from

        JXPathContext multiValueContext = jctx.getRelativeContext(ptr);
        // build a jxpath iterator for pointers
        Iterator rowPointers = multiValueContext.iterate(this.rowPath);

        LinkedList list = new LinkedList();

        while (rowPointers.hasNext()) {
            Object value = rowPointers.next();

            if (value != null && convertor != null) {
                if (value instanceof String) {
                    value = convertor.convertFromString((String) value, convertorLocale, null);
                } else {
                    getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
                }
            }

            list.add(value);
        }

        widget.setValue(list.toArray());
    }

    if (getLogger().isDebugEnabled())
        getLogger().debug("done loading values " + toString());
}