Java Utililty Methods Queue Usage

List of utility methods to do Queue Usage

Description

The list of methods to do Queue Usage are organized into topic(s).

Method

doubleaddElementsToQueueInSingleThread(int numberOfElements, Queue queue, int element)
add Elements To Queue In Single Thread
long t = System.nanoTime();
for (int i = 0; i < numberOfElements; i++) {
    queue.add(element);
t = System.nanoTime() - t;
return t / Math.pow(10, 9);
QueueaddStringArraytoQueue(Queue set, String[] array)
add String Arrayto Queue
for (String string : array) {
    set.add(string);
return set;
StringasString(Queue values)
as String
StringBuilder sb = new StringBuilder();
sb.append("[");
boolean first = true;
for (byte[] bs : values) {
    if (first) {
        first = false;
    } else {
        sb.append(", ");
...
StringbQToString(Queue bQ)
b Q To String
byte[] bytes = new byte[bQ.size()];
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = bQ.poll();
return new String(bytes);
ListconvertQueueToArray(Queue q)
convert Queue To Array
Queue<K> temp = new PriorityQueue<K>(q);
List<K> list = new ArrayList<K>();
while (temp.size() > 0)
    list.add(temp.poll());
return list;
voidelementFail(Queue q)
element Fail
try {
    q.element();
    throw new RuntimeException("Exception should have thrown");
} catch (NoSuchElementException e) {
Eget(Queue queue, int index)
get
E result = null;
int i = 0;
for (E e : queue) {
    if (i == index) {
        result = e;
        break;
    i++;
...
ListgetAllElementsFromQueueAsList(Queue queue)
get All Elements From Queue As List
final int size = queue.size();
List<Type> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
    result.add(queue.poll());
return result;
booleanisListBased(Class type)
Return whether the supplied type (collection) is list based.
if (type == null) {
    return false;
} else if (java.util.List.class.isAssignableFrom(type)) {
    return true;
} else if (java.util.Queue.class.isAssignableFrom(type)) {
    return true;
return false;
...
booleanisQueue(final Object value, final boolean acceptNull)
Returns true if the given object is an instance of Queue .
return isType(Queue.class, value, acceptNull);