Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

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

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:Main.java

public static <T> List<T> toList(Iterable<T> it) {
    if (it instanceof List) {
        return (List<T>) it;
    }/*w w  w . j av  a 2 s . c  o  m*/
    final List<T> result = new LinkedList<T>();
    for (final T t : it) {
        result.add(t);

    }
    return result;
}

From source file:Main.java

/**
 * Copy Iterable content to a list. /*from  w  ww  .  j a va  2  s  .  c om*/
 * @param iter : Iterable 
 * @return
 */
public static <E> Collection<E> makeCollection(Iterable<E> iter) {
    Collection<E> list = new LinkedList<E>();
    for (E item : iter) {
        list.add(item);
    }
    return list;
}

From source file:Main.java

private static synchronized List<Activity> getActivityList() {
    if (sActivitiesList == null) {
        sActivitiesList = new LinkedList<Activity>();
    }//from   w  w  w. j  av a2 s  . c om
    return sActivitiesList;
}

From source file:Main.java

public static LinkedList<String> retrieveStringFromCursor(Cursor cursor, String columnName) {
    LinkedList<String> result = new LinkedList<String>();

    if (null == cursor || 0 == cursor.getCount()) {
        return result;
    }//  w ww  .j  av a  2s .c  om

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            String str = cursor.getString(cursor.getColumnIndexOrThrow(columnName));
            result.add(str);
        }
    } catch (Exception e) {
        //do nothing.
    } finally {
        cursor.close();
    }

    return result;
}

From source file:Main.java

/**
 * @param name/*from ww  w.j  a  va 2  s.  c o  m*/
 * @return list of threads
 */
public static List<Thread> listThreadGroup(String name) {
    List<Thread> threads = new LinkedList<Thread>();
    ThreadGroup threadGroup = getThreadGroupByName(name, null);
    if (threadGroup != null) {
        int count = threadGroup.activeCount();
        Thread threadArray[] = new Thread[count];
        int threadCount = Thread.enumerate(threadArray);
        for (int index = 0; index < threadCount; index++) {
            threads.add(threadArray[index]);
        }
    }
    return threads;
}

From source file:Main.java

public static List<Element> getElementCollectionByTagName(Element element, String tagName) {
    List<Element> result = new LinkedList<Element>();
    NodeList nodeList = element.getElementsByTagName(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            result.add((Element) node);
        }//  w  w w . j  av a2s .  co m
    }
    return result;
}

From source file:Main.java

public static List<Element> childs(Node node) {
    NodeList children = node.getChildNodes();
    List<Element> result = new LinkedList<Element>();
    for (int i = 0; i < children.getLength(); i++) {
        Node c = children.item(i);
        if (c.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }/*  ww w. j  a  va2 s.  c  o m*/
        result.add((Element) c);
    }
    return result;
}

From source file:Main.java

public static String[] intersect(String[] arr1, String[] arr2) {
    Map<String, Boolean> map = new HashMap<String, Boolean>();
    LinkedList<String> list = new LinkedList<String>();
    for (String str : arr1) {
        if (!map.containsKey(str)) {
            map.put(str, Boolean.FALSE);
        }/*from   ww  w.j a  va2  s  .  c  o  m*/
    }

    for (String str : arr2) {
        if (map.containsKey(str)) {
            map.put(str, Boolean.TRUE);
        }
    }

    for (Map.Entry<String, Boolean> e : map.entrySet()) {
        if (e.getValue().equals(Boolean.TRUE)) {
            list.add(e.getKey());
        }
    }

    String[] result = {};
    return list.toArray(result);
}

From source file:Main.java

public static Collection<Node> search_nodes_by_name(Node root, String name) {
    Collection<Node> result = new LinkedList<Node>();
    if (root.getNodeName().equals(name))
        result.add(root);//from   w  ww  .j  a v a  2 s . c  om
    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); ++i) {
        Node child = list.item(i);
        Collection<Node> ret = search_nodes_by_name(child, name);
        result.addAll(ret);
    }
    return result;
}

From source file:Main.java

public static <T> List<List<T>> splitEvery(Iterable<T> input, int size) {
    List<List<T>> listOfList = new LinkedList<List<T>>();
    List<T> list = null;/*from   w  ww .j  a  v  a 2 s . com*/
    int index = 0;
    for (T t : input) {
        if ((index % size) == 0) {
            list = new ArrayList<T>(size);
            listOfList.add(list);
        }
        index++;
        list.add(t);
    }
    return listOfList;
}