Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;
import java.util.Queue;

public class Main {
    /**
     * Creates a list by pulling off the head of a queue one item at a time and
     * adding it to an output list. The input queue is emptied by this method.
     * 
     * @param <T>
     * @param queue
     * @param outputList
     * @param reverse
     *            whether or not to reverse the resulting list
     * @return
     */
    public static <T> List<T> createList(Queue<T> queue, List<T> outputList, boolean reverse) {
        if (outputList == null) {
            outputList = new ArrayList<T>(queue.size());
        }
        while (!queue.isEmpty()) {
            outputList.add(queue.poll());
        }
        if (reverse) {
            Collections.reverse(outputList);
        }
        return outputList;
    }
}