2

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).

1
  • 1
    In 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. Commented Feb 1, 2017 at 20:41

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Isn't a structure technically someting abstract in itself? Taken that it describes the organization of something. Or is my english failing me here?
According to the Oxford dictionary (en.oxforddictionaries.com/definition/abstract) a structure per se does not have to be abstract (e.g. when that something it describes is concretely defined). It can be abstract if something it defines is abstract, but can also be very concrete. In Java interfaces, abstract classes, generic classes and any non-final class one could consider abstract. The former three are described above, the latter you can extend or override with another class, thus potentially permitting abstracting away some logic.
Following the definition of "abstract" i am inclined to agree, like in "wooden structure". Nevertheless when i consider the definition of "structure" as "The arrangement of and relations between the parts or elements of something complex" that sounds pretty abstract to me, but that may be a rather philosophical point of view. Sorry, overlooked the 2nd definition variant - "A building or other object constructed from several parts" - that could be pretty not abstract.
Well, the structure as in data structure is not described accurately by that definition, but by the second one in the same article: "2. A building or other object constructed from several parts" -- a programming language data structure is to my knowledge normally exactly this. But then take the first definition you provided, replace complex with e.g. composite, "made of several parts" and it will be perfectly non-abstract, it is a concrete arrangement and concrete relations of a composite object.
Following that line of thought, everything but primitives in informatics could fall under the term "structure", a data structure being one that represents a set of data (in oposition to an utility structure, like a helper class). Conclusion: every class generating or describing a stateful object would be a data structure. If you now decide that "abstract" in this context means "not to be instantiated", it would be a valid term.
2

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

For your comment : Invoking an interface with a new operator will never work and not just for this case. You would always have to provide an implementation class / object to capture it.
I know. Never said otherwise. But try public class List extends ArrayList{} for instance. It's all a matter of imports... ;)
Exactly but that List class would be your own implementation class with a different package structure and will have nothing to do with a List interface from java.util.List. We might be in the same page for all I know.
Of course it would be. Yours or someone elses. I was just being precise with the reference. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.