Example usage for java.util Collections reverse

List of usage examples for java.util Collections reverse

Introduction

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

Prototype

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void reverse(List<?> list) 

Source Link

Document

Reverses the order of the elements in the specified list.

This method runs in linear time.

Usage

From source file:Main.java

public static <T> List<T> createReversedList(List<T> inputList) {
    List<T> result = new ArrayList<T>(inputList); // avoid changing the input
    Collections.reverse(result);
    return result;
}

From source file:in.sc.main.ABC.java

public static List reverse(List list) {
    Collections.reverse(list);

    return list;

}

From source file:Main.java

public static <T> List<T> reverse(List<T> input) {
    List<T> output = new ArrayList<>(input);
    Collections.reverse(output);
    return output;
}

From source file:Main.java

public static void reverse(final List<?> list) {
    Collections.reverse(list);
}

From source file:Main.java

/**
 * Note: This method makes an in-memory copy of the elements.
 * This can be inefficient for large lists.
 *///from   www .j a  va  2  s  . co  m
public static <T> Iterator<T> reverse(Iterator<T> it) {
    List<T> list = Lists.newArrayList(it);
    Collections.reverse(list);
    return list.iterator();
}

From source file:at.bitfire.davdroid.DavUtils.java

public static String lastSegmentOfUrl(@NonNull String url) {
    // the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy
    List<String> segments = new LinkedList<>(HttpUrl.parse(url).pathSegments());
    Collections.reverse(segments);

    for (String segment : segments)
        if (!StringUtils.isEmpty(segment))
            return segment;

    return "/";
}

From source file:Main.java

public static <T> List<T> reverse(Collection<T> input) {
    List<T> output = new ArrayList<>(input);
    Collections.reverse(output);
    return output;
}

From source file:Main.java

/**
 * Finds element in DOM tree//www  .j  a v a2 s  .  c  o m
 * @param topElm Top element
 * @param nodeName Node name
 * @return returns found node
 */
public static List<Node> findNodesByType(Element topElm, int type) {
    List<Node> retvals = new ArrayList<Node>();
    if (topElm == null)
        throw new IllegalArgumentException("topElm cannot be null");
    synchronized (topElm.getOwnerDocument()) {
        Stack<Node> stack = new Stack<Node>();
        stack.push(topElm);
        while (!stack.isEmpty()) {
            Node curElm = stack.pop();
            if (curElm.getNodeType() == type) {
                retvals.add(curElm);
            }
            List<Node> nodesToProcess = new ArrayList<Node>();

            NodeList childNodes = curElm.getChildNodes();
            for (int i = 0, ll = childNodes.getLength(); i < ll; i++) {
                Node item = childNodes.item(i);
                //stack.push((Element) item);
                nodesToProcess.add(item);
            }
            Collections.reverse(nodesToProcess);
            for (Node node : nodesToProcess) {
                stack.push(node);
            }
        }
        return retvals;
    }
}

From source file:Main.java

public TreePath getPath(TreeNode node) {
    List<TreeNode> list = new ArrayList<TreeNode>();

    while (node != null) {
        list.add(node);//from  w w w  .  j av a  2 s  .c  o m
        node = node.getParent();
    }
    Collections.reverse(list);

    return new TreePath(list.toArray());
}

From source file:Main.java

/**
 * Reverse the given list and returns it.
 * @param <T> the type of the instance contained into the specified list
 * @param list the list to reverse//from w ww .j a v  a 2 s .  c om
 * @return the specified list that has been reversed (same instance)
 */
public static <T> List<T> reverse(List<T> list) {
    Collections.reverse(list);
    return list;
}