[Java] ArrayDeque

ArrayDeque is implemented by array. When capacity increased, it will create a new array and copy the old one to new.

import java.util.*;
import java.lang.reflect.*;

public class ArrayDequePerformance {
  public static void main(String[] args) {
    try {
      long s1 = now();
      ArrayDeque<Integer> q = new ArrayDeque<>();
      for (int i = 0; i < 16777215; ++i) {
      long e1 = now();
      System.out.println(e1 - s1);

      Field f = q.getClass().getDeclaredField("elements");
      f.setAccessible (true);
      Object[] ar = (Object[])f.get(q);

      long s2 = now();
      long e2 = now();
      System.out.println(e2 - s2);
    } catch (Exception e) {
  public static long now() {
    return System.currentTimeMillis();

Recommended Posts

[Java] ArrayDeque
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface
Java9 collection
Java basics