Summary of the major non-concurrent, non-synchronized Java collections

Studying up for a job interview. Big emphasis on concurrency in this company, which I’m inexperienced with. Reading Java Concurrency In Practice, and I’m finding myself reviewing the basic collection types over and over, so I’m putting them down here once and for all.

Collection: An interface representing an unordered “bag” of items, called “elements”. The “next” element is undefined (random).

  • Set: An interface representing a Collection with no duplicates.
    • HashSet: A Set backed by a Hashtable. Fastest and smallest memory usage, when ordering is unimportant.
    • LinkedHashSet: A HashSet with the addition of a linked list to associate elements in insertion order. The “next” element is the next-most-recently inserted element.
    • TreeSet: A Set where elements are ordered by a Comparator (typically natural ordering. Slowest and largest memory usage, but necessary for comparator-based ordering.
    • EnumSet: An extremely fast and efficient Set customized for a single enum type.
  • List: An interface representing an Collection whose elements are ordered and each have a numeric index representing its position, where zero is the first element, and (length - 1) is the last.
    • ArrayList: A List backed by an array, where the array has a length (called “capacity”) that is at least as large as the number of elements (the list’s “size”). When size exceeds capacity (when the (capacity + 1)-th element is added), the array is recreated with a new capacity of (new length * 1.5)–this recreation is fast, since it uses System.arrayCopy(). Deleting and inserting/adding elements requires all neighboring elements (to the right) be shifted into or out of that space. Accessing any element is fast, as it only requires the calculation (element-zero-address + desired-index * element-size) to find it’s location. In most situations, an ArrayList is preferred over a LinkedList.
    • LinkedList: A List backed by a set of objects, each linked to its “previous” and “next” neighbors. A LinkedList is also a Queue and Deque. Accessing elements is done starting at the first or last element, and traversing until the desired index is reached. Insertion and deletion, once the desired index is reached via traversal is a trivial matter of re-mapping only the immediate-neighbor links to point to the new element or bypass the now-deleted element.
  • Map: An interface representing an Collection where each element has an identifying “key”–each element is a key-value pair.
    • HashMap: A Map where keys are unordered, and backed by a Hashtable.
    • LinkedhashMap: Keys are ordered by insertion order.
    • TreeMap: A Map where keys are ordered by a Comparator (typically natural ordering).
  • Queue: An interface that represents a Collection where elements are, typically, added to one end, and removed from the other (FIFO: first-in, first-out).
  • Stack: An interface that represents a Collection where elements are, typically, both added (pushed) and removed (popped) from the same end (LIFO: last-in, first-out).
  • Deque: Pronounced “deck”. A linked list that is typically only added to and read from either end (not the middle).

Basic collection diagrams:

Comparing the insertion of an element with an ArrayList and LinkedList:

This is also an answer on Stack Overflow. Please consider up-voting it.

Ways to quickly access favorite folders in XYplorer

In the Windows Explorer replacement, XYplorer, between custom toolbar buttons (CTBs), the catalog, scripting, and paper folders, there are plenty of ways to quickly access your favorite folders. I use CTBs and the catalog. Here’s the CTB that lists my favorite folders on the C:\ drive when left-clicked, and goes to the root when right-clicked:

Snip: CTB 1
  XYplorer 15.00.0104, 3/14/2015 9:04:59 PM
  Left-click: Sub-directory / Right-click: Root
  "data_jeffy\code (use catalog for XBN-Java)"
  " doc root"
  "Secondary applications (paper)"
     ::goto "paper:Other applications"
  ::goto "C:\"

I have a CTB like this for each of the three drives I work on.

This is the CTB I use to switch between catalogs:

Snip: CTB 1
  XYplorer 15.00.0104, 3/14/2015 9:08:36 PM
  Open catalog
     tabset("save", "1"); tabset("save", "2"); tabset("load", "working_left_pane", "1"); tabset("load", "working_right_pane", "2"); catalogload "working.dat";
     tabset("save", "1"); tabset("save", "2"); tabset("load", "xbn_left_pane", "1"); tabset("load", "xbn_right_pane", "2"); catalogload "git_repositories_xbnjava.dat";
  "Non-XBN-Java repositories"
     tabset("save", "1"); tabset("save", "2"); tabset("load", "nonxbn_left_pane", "1"); tabset("load", "nonxbn_right_pane", "2");    catalogload "git_repositories_non_xbnjava.dat";
  "Django Auth Tutorial"
     tabset("save", "1"); tabset("save", "2"); tabset("load", "Q_left_pane", "1"); tabset("load", "Q_right_pane", "2"); catalogload "django_auth_tutorial.dat";
     tabset("save", "1"); tabset("save", "2"); tabset("load", "singing_left_pane", "1"); tabset("load", "singing_right_pane", "2"); catalogload "singing.dat";

  "File > Settings Special > Save Catalog"
     :: #186
  "Tools > List Management > Recent Catalogs..."
     :: #634
  "Tools > List Management > Recently Included Catalogs..."
     :: #636
  "Window > Show Catalog"
     :: #664
  "Window > Arrangement > Tree and Catalog Stacked"
     :: #687
  "Window > Arrangement > Catalog First"
     :: #686
  "Miscellaneous > Focus Functions > Focus Catalog"
     :: #1015
  "Load global catalog as include"
     load "open_catalog\_unload_all_include_global";
  "Open gloabl catalog"
     catalogload "_global.dat", "p";

(The right-click items are rarely-used. It’s just where I store interesting catalog-related commands.)

Notice that each catalog, when switched to, reloads the tabsets into both panes, that were there the last time I was using that catalog. This is an awesome thing. Each catalog is like its own workspace (and creates the tabsets if they don’t exist yet). the only thing missing that would make this perfect, is to do the same thing with the toolbar: Have a specific set of CTBs associated to each catalog, and auto-set themselves each time I switch catalogs. This is currently possible, but not yet ideal.

And here, for example, is my “Non-XBN-Java repositories” catalog:

Most categories (such as XYplorer settings) have the go-to, copy-path, and open-in-command-prompt items, and may have additional items (like the extra ones in Sublime).