It's all about terminology. Can I say that the List is an abstract data type and the ArrayList is a data structure? So, the Java Collection Framework is group of ASTs and corresponding DSs (implementations).
-
1In a word (so as to attain the minimum number of characters here), yes. Don't use backslashes in English: they are really only for Windows filenames.user207421– user2074212017-02-01 20:41:03 +00:00Commented Feb 1, 2017 at 20:41
2 Answers
An interface (not only in Java, but also in e.g. C#, Go etc.) is a definition of the API, a contract, that specifies which methods can be invoked on instances implementing the interface. Interfaces neither hold any data nor actually implement the contract themselves. In that sense one can say that an interface is an abstract data structure. List is an interface, that is it is a contract describing how one can operate with an ordered collection of data. An interface can extend another interface with further contract methods. As the List interfaces describes an ordered collection of data it makes perfect sense that it extends the Collection interface, which simply defines a contract for a generic collection of data (e.g. without referring to a specific ordering or insertion rules). Again, one can describe that as an abstract data structure.
ArrayList is one of possible implementations of the List interface. As such it also implements the Collection interface. So it is a concrete data structure (and a collection itself) implementing more than one abstract data structures. However, there are also abstract classes in Java, those which have some methods left unimplemented. These are also abstract data structures, but are not interfaces. So an interface in Java is an abstract data structure, but not vice versa.
Furthermore, one can have an abstract data structure (abstract class) implementing an interface (an abstract data structure itself). A thought exercise for you: figure what is the meaning of that :)
But then, what is abstract? A concrete class parametrized with a generic type is in a way an abstract data structure as it abstracts away algorithms applicable to different classes that can be used to subsitute the generic type. As ArrayList is itself one of those concrete implementations that uses Java generics to define the data type it operates on, it is itself an abstract data structure, but in a different way from interfaces or abstract classes. The abstract data structure is, in this sense, an ill-defined term.
5 Comments
List is an Interface. You always have an implementation behind it, and you cannot go like:
List list = new List(); // does not work. At least not with java.util.List
ArrayList is one of the implementations that implements the List interface.
So, thus said, you could put it that way.
4 Comments
public class List extends ArrayList{} for instance. It's all a matter of imports... ;)