In fact, there is a boxless data structure provided by the JDK libraries. If you look at the LinkedHashMap constructor:
public LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder) { super(initialCapacity, loadFactor); this.accessOrder = accessOrder; }
there is an additional parameter accessOrder . Based on this, the newly added object will be moved to the end of the list ( accessOrder - true ) or will remain in the same place ( accessOrder - false ).
To create a Set with these characteristics, you will need to use this factory method from java.util.Collections : newSetFromMap(LinkedHashMap(initialCapacity, loadFactor, accessOrder))
Keep in mind that the accessOrder property accessOrder responsible for all interactions with this element - if you call get on the HashMap , it will also reorder (which shouldn’t affect you, since the Set interface does not provide a get method for the wrapped HashMap , just saying )
source share