简体   繁体   中英

Is there an in-built linked list node in Java libraries

The LinkedList class operates over the entity and the Node is no directly exposed. Is there an in-built library which provides the traditional LinkedList interface?

PS: I see the Apache Collections LinkedList Node , is there one within Java librares?

Not in the standard library. You would need to find a third party library. There are many sites that will show you how to write one.

Java collection API has LinkedList that is internally organized pretty muck like you desire.

But to make direct use of all these previsous and next references that each node has you should exploit ListIterator , getting it like that

iterator = linkedList.listIterator()

The last one has an API with a bit unintuitive behaviour, but it allows you to facilitate your code with all advantages of a linked list data structure:

  • you can navigate back and forth by

    iterator.next() iterator.previous()

  • you can modify the list with

    iterator.add() iterator.remove() iterator.set()

  • you also can shift indices both ways and do the rest of things an iterator usually does, but bothways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM