Reputation: 23
I'm learning java and Abstract Data Types and I'm getting a little bit confused.
Basically, from what I understood, Abstract Data Types are something that is defined, but not implemented. So we have the API of the Abstract Data Type and we need to implement those methods specified in the API. For example, we have a Stack and we can implement it by using arrays, nodes, etc... As an example, to declare those objects we do:
Stack ex = new ArrayStack<>(); or Stack ex = new NodeStack<>();
My problem is, we can also do Stack ex = new Stack<>(); without implementing anything. In this case which implementation are we using? What's the point of implementing it then? Can we choose which implementation we are going to use without implementing it ourselves? I'm so lost.
Another example, why do we need to create nodes to implement ADTs if we can use a LinkedList directly? Is it for leaning purposes only or are they something different?
Thanks for the help!
Upvotes: 1
Views: 723
Reputation: 5990
You're correct in your description of an abstract data type. However if you are referring to java.util.Stack<E>
, it isn't abstract and you can check the documentation here.
Edit
A LinkedList<E>
is also not abstract, but is an implementation of the List<E>
interface. The Node<E>
class is just used in the LinkedList<E>
implementation. Apart from for learning purposes or using a Node
style structure elsewhere, there is no need to create your own version.
Upvotes: 1