In Java 8 (until Java 11) there is a method 'getObjectSize' in 'jdk.nashorn.internal.ir.debug.ObjectSizeCalculator' class.
This method lets us measure any Object size, containing any other elements or Objects inside it (that's called deep Object size)
'getObjectSize' was added in Java 8 as a part of 'Nashorn JavaScript engine' and depricated in Java 11.
This code is an example, showing how to get exact byte size of a single Integer in any Collections Framework class (or deep size size of any other object in Java)
(a single +1 Integer element costs):
Vector, Stack, ArrayList: 16 byte
(one link 8 byte + one Integer 8 byte)
LinkedList: 40 byte
(node 8 byte, prev\next\current link 8 byte each, Integer 8 byte)
ArrayDeque, PriorityQueue: 16 byte
(one link 8 byte + one Integer 8 byte)
HashSet: 48 byte
(node 8 byte, key\value links 8 byte each, key\value Integers 8 byte each, next element in bucket link 8 byte)
LinkedHashSet: 56 byte
(HashSet size + one link 8 byte)
TreeSet: 56 byte
(node 8 byte, key\value links 8 byte each, key\value Integers 8 byte each, two child elements 8 byte each)
HashMap: 48 byte
(same as HashSet)
LinkedHashMap: 56 byte
(same as HashMap)
TreeMap: 56 byte
(same as TreeSet)