Home > other >  Is it possible to access to java.util.LinkedList node directly?
Is it possible to access to java.util.LinkedList node directly?

Time:04-28

Is it possible to access to java.util.LinkedList node directly, and manually swap two nodes by change next and prev links?

CodePudding user response:

No. The node is not publicly accessible, and it's an implementation detail that may change or even disappear in a given Java runtime.

Yes. With sufficient effort and ongoing care, you can use reflection to manipulate the normally inaccessible innards of a particular implementation.

I suspect this might be an XY problem, and if you described your goal, it might be that a different collection would work better.


For an LRU cache, you could use LinkedHashMap, with the access-order flag set.

  • Related