# Analyzing Java Collection Usage

A collection is an object that are used to store, retrieve and manipulate the data. Memory Analyzer offers the following queries to analyze java collections:

Array Fill Ratio Query | Prints a frequency distribution of fill ratios of non-primitive arrays. The fill ratio is the proportion of non-null elements in the array. The arrays are then accumulated into as many segments as parameterized. Primitive arrays cannot have null values so this query works only on object arrays.
Arrays Grouped by Size Query | Distribution histogram of given arrays grouped by the size.

Collection Fill Ratio Query

Prints a frequency distribution of fill ratios of given collections. The following collections can be used for the query:

-     java.awt.RenderingHints

-     java.beans.beancontext.BeanContextSupport

-     java.lang.ThreadLocal$ThreadLocalMap

-     java.util.ArrayDeque

-     java.util.ArrayList

-     java.util.Arrays$ArrayList

-     java.util.Collections$CheckedCollection

-     java.util.Collections$CheckedMap

-     java.util.Collections$CheckedSet

-     java.util.Collections$EmptyList

-     java.util.Collections$EmptyMap

-     java.util.Collections$EmptySet

-     java.util.Collections$SetFromMap

-     java.util.Collections$SingletonList

-     java.util.Collections$SingletonSet

-     java.util.Collections$SynchronizedCollection

-     java.util.Collections$SynchronizedSet

-     java.util.Collections$UnmodifiableCollection

-     java.util.Collections$UnmodifiableSet

-     java.util.concurrent.ArrayBlockingQueue

-     java.util.concurrent.ConcurrentHashMap

-     java.util.concurrent.ConcurrentLinkedDeque

-     java.util.concurrent.ConcurrentLinkedQueue

-     java.util.concurrent.ConcurrentSkipListMap

-     java.util.concurrent.CopyOnWriteArrayList

-     java.util.concurrent.DelayQueue

-     java.util.concurrent.LinkedBlockingDeque

-     java.util.concurrent.LinkedBlockingQueue

-     java.util.concurrent.LinkedTransferQueue

-     java.util.concurrent.SynchronousQueue

-     java.util.EnumMap

-     java.util.EnumSet

-     java.util.HashMap

-     java.util.HashSet

-     java.util.Hashtable

-     java.util.IdentityHashMap

-     java.util.ImmutableCollections$List0

-     java.util.ImmutableCollections$Set1

-     java.util.LinkedHashSet

-     java.util.LinkedList

-     java.util.PriorityQueue

-     java.util.Properties

-     java.util.TreeSet

-     java.util.WeakHashMap

-     java.util.jar.Attributes

-     javax.script.SimpleBindings

One additional custom collection (e.g. non-JDK) collection can be specified by the 'collection', 'size_attribute' and 'array_attribute' argument.

Collections Grouped By Size Query

Distribution histogram of given collections by their size. The following collections can be used for the query. Known collections:

-     java.awt.RenderingHints

-     java.beans.beancontext.BeanContextSupport

-     java.lang.ThreadLocal$ThreadLocalMap

-     java.util.ArrayDeque

-     java.util.ArrayList

-     java.util.Arrays$ArrayList

-     java.util.Collections$CheckedCollection

-     java.util.Collections$CheckedMap

-     java.util.Collections$CheckedSet

-     java.util.Collections$EmptyList

-     java.util.Collections$EmptyMap

-     java.util.Collections$EmptySet

-     java.util.Collections$SetFromMap

-     java.util.Collections$SingletonList

-     java.util.Collections$SingletonMap

-     java.util.Collections$SingletonSet

-     java.util.Collections$SynchronizedCollection

-     java.util.Collections$SynchronizedMap

-     java.util.Collections$SynchronizedSet

-     java.util.Collections$UnmodifiableCollection

-     java.util.Collections$UnmodifiableMap

-     java.util.Collections$UnmodifiableSet

-     java.util.concurrent.ArrayBlockingQueue

-     java.util.concurrent.ConcurrentHashMap

-     java.util.concurrent.ConcurrentLinkedDeque

-     java.util.concurrent.ConcurrentLinkedQueue

-     java.util.concurrent.ConcurrentSkipListMap

-     java.util.concurrent.ConcurrentSkipListSet

-     java.util.concurrent.CopyOnWriteArrayList

-     java.util.concurrent.CopyOnWriteArraySet

-     java.util.concurrent.DelayQueue

-     java.util.concurrent.LinkedBlockingDeque

-     java.util.concurrent.LinkedBlockingQueue

-     java.util.concurrent.LinkedTransferQueue

-     java.util.concurrent.SynchronousQueue

-     java.util.EnumMap

-     java.util.EnumSet

-     java.util.HashMap

-     java.util.HashSet

-     java.util.Hashtable

-     java.util.IdentityHashMap

-     java.util.ImmutableCollections$List0

-     java.util.ImmutableCollections$List1

-     java.util.ImmutableCollections$List2

-     java.util.ImmutableCollections$ListN

-     java.util.ImmutableCollections$MapN

-     java.util.ImmutableCollections$Set0

-     java.util.ImmutableCollections$Set1

-     java.util.ImmutableCollections$Set2

-     java.util.ImmutableCollections$SetN

-     java.util.jar.Attributes

-     java.util.LinkedHashMap

-     java.util.LinkedHashSet

-     java.util.LinkedList

-     java.util.PriorityQueue

-     java.util.Properties

-     java.util.TreeMap

-     java.util.TreeSet

-     java.util.Vector

-     java.util.WeakHashMap

-     javax.script.SimpleBindings

-     javax.swing.UIDefaults

One additional custom collection (e.g. non-JDK) collection can be specified by the 'collection', 'size_attribute' and 'array_attribute' argument.

Extract List Values Query | Lists elements of a single LinkedList, ArrayList, Vector, CopyOnWriteArrayList, PriorityQueue, ArrayDeque object.
Hash Entries Query | Extracts the key-value pairs from hash maps and hashtables.
Extract Hash Set Values Query | Lists elements of a single HashSet.

Map Collision Ratio Query

Prints a frequency distribution of the collision ratios of map-like collections. The following map-like collections can be used for the query.

-     java.util.HashMap

-     java.util.Properties

-     java.util.Hashtable

-     java.util.WeakHashMap

-     java.util.concurrent.ConcurrentHashMap$Segment

-     java.util.HashSet

-     java.util.concurrent.ConcurrentHashMap

-     java.util.concurrent.ConcurrentSkipListMap

-     java.util.concurrent.ConcurrentSkipListSet

-     java.util.Collections$CheckedMap

-     java.util.Collections$CheckedSet

-     java.util.Collections$SynchronizedMap

-     java.util.Collections$SynchronizedSet

-     java.util.Collections$UnmodifiableMap

-     java.util.Collections$UnmodifiableSet

-     java.util.LinkedHashMap

-     java.util.LinkedHashSet

-     java.util.ImmutableCollections$MapN

-     java.util.jar.Attributes

-     java.awt.RenderingHints

-     java.beans.beancontext.BeanContextSupport

-     java.lang.ThreadLocal$ThreadLocalMap

-     javax.script.SimpleBindings

-     javax.swing.UIDefaults

One additional custom map-like (e.g. non-JDK) collection can be specified by the 'collection', 'size_attribute' and 'array_attribute' argument.

Primitive Arrays with a Constant Value Query | Lists all primitive arrays (from a selection) which are filled with one and the same value

All these queries are accessible from the toolbar drop-down menu: Open Query Browser > Java Collections

There are also available from the pop-up context menu using mouse button 2 on a selection of objects from a previous query. Unsuitable queries for the selection are filtered out and are not shown, so for example a Hash Entries query would not be offered for a selection of `ArrayList` objects. All the collection queries can be seen from the pop-up context menu using: Search Queries... > Java Collections Any query can then be selected and run.