Why the ArrayList implements the List interface

Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?

899440 wrote:
Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?I dont think there's any specific reason for that. In my opinion its redundant. May be its added for clarity so that from the documentation its obivous that ArrayList implements List.
May be there's something which I am missing regarding this?

Similar Messages

  • Why the HashMap implements the Map interface twice

    See the type hierarchy below:
    HashMap<K,V>
    &#9475;
    &#9507;AbstractMap<K,V>
    &#9475;&#9475;
    &#9475;&#9495;Map<K,V>
    &#9495;Map<K,V>
    The HashMap extends AbstractMap, which implements Map. So the HashMap has already implements Map, and has the Map type. But the HashMap's declaration still contains "implements Map".
    So why the HashMap implements the Map interface twice?
    Thanks in advance.

    georgemc wrote:
    Maybe the guy who wrote HashMap wanted to make it clear that HashMap implemented Map, rather than rely on you looking further up the hierarchy to find outYes, it does make the Javadoc clearer. If they hadn't done that then there would have been legions of newbies who couldn't tell that HashMap implemented Map and thousands of "I have a doubt, does HashMap implement Map" questions here.

  • Why does  ArrayList implement List when extending AbstractList

    Hi
    I am unable to understand why would the ArrayList class implement the List interface, when it is already extending the AbstarctList class. If anyone can explain, it would be a great help.

    Why does ArrayList implement List when extendingAbstractList
    It is a question of style. ArrayList'simplementing
    List is a crucial piece of information, whereasits
    extending AbstractList is a kind of implementation
    detail. If would not matter much to the user if it
    did not extend AbstractList but implemented List
    directly.So why don't those subclasses of ArrayList step up
    and implement List again? I agree, extending
    ArrayList is an implementation detail, and in fact
    perhaps they should have made ArrayList a field
    rather than a superclass...Because those subclasses job is not to be a List but to be an extension of ArrayList. In general if you wanted to be a List you would be extending AbstractList. You don't just implement List because you happen to have the right methods, you implement List because you feel being a List is part of that classes main behavior.
    Its a suttle point but I feel its more than a matter of style. Its a matter of correctness.
    Also, ArrayList could use composition by having an AbstractList member within itself. In this case it would implement List as well and achieve the same result. Letting users know it intends to fill the role of a List.

  • Why does ArrayList "implement" List, when it extends AbstractList?

    I never noticed this before, and so i was wondering if there's a good explanation for it: If you look at how ArrayList is defined, you'll see this:
    ===
    public class ArrayList
    extends AbstractList
    implements List, RandomAccess, Cloneable, Serializable
    ===
    But AbstractList, which ArrayList extends, already implements List, like this:
    ===
    public abstract class AbstractList
    extends AbstractCollection
    implements List
    ===
    So, why does ArrayList list List in the list of implements? (that's kind of a confusing sentence, read it twice) By extending AbstractList, it's already clear that it implements List - now it's like it's implementing it twice (which doesn't hurt of course, but it doesn't help either.) This seems inconsistent with other parts of the API, where usually in cases like this (with an abstract class being extended) the interface isn't listed again in the final concrete class. For instance:
    public class TitledBorder
    extends AbstractBorder
    and:
    public abstract class AbstractBorder
    extends Object
    implements Border, Serializable
    but:
    TiledBorder doesn't mention Border in its (non-existent) list of implements.
    Any ideas?
    -- Niek

    Surely enough the AbstractList
    takes care of all the burden (like I wrote before),
    but the ArrayList (re)implements the List interface
    for
    very sound reasons. If it didn't, the
    o.getClass().getInterfaces() would've missed the List
    interface,Since AbstractList implements List, ArrayList has an implicit "implements List." However, as you say, getInterfaces() doesn't produce that.
    So you're saying that the VM has to do something different to find the method? I don't think so. The compiler may have to work harder, but in both cases, the VM does an invokeinterface. The javap output looks the same in a copule of test classes I created.
    public interface I1 {
        public void i1Meth();
        public void i1Meth2();
    public abstract class IA implements I1 {
        public void i1Meth() {}
    public class IC1 extends IA implements I1 {
        public void i1Meth2() {}
        void dummy() {
            I1 i1 = new IC1();
            i1.i1Meth();
            i1.i1Meth2();
    import java.util.*;
    public class IC2 extends IA {
        public void i1Meth2() {}
        void dummy() {
            I1 i1= new IC2();
            i1.i1Meth();
            i1.i1Meth2();
        public static void main(String[] args) {
            System.out.println(Arrays.asList(IC2.class.getInterfaces()));
            System.out.println(Arrays.asList(IC1.class.getInterfaces()));
    Compiled from "IC1.java"
    public class IC1 extends IA implements I1{
    void dummy();
      Code:
       0:   new     #2; //class IC1
       3:   dup
       4:   invokespecial   #3; //Method "<init>":()V
       7:   astore_1
       8:   aload_1
       9:   invokeinterface #4,  1; //InterfaceMethod I1.i1Meth:()V
       14:  aload_1
       15:  invokeinterface #5,  1; //InterfaceMethod I1.i1Meth2:()V
       20:  return
    Compiled from "IC2.java"
    public class IC2 extends IA{
    void dummy();
      Code:
       0:   new     #7; //class IC2
       3:   dup
       4:   invokespecial   #8; //Method "<init>":()V
       7:   astore_1
       8:   aload_1
       9:   invokeinterface #9,  1; //InterfaceMethod I1.i1Meth:()V
       14:  aload_1
       15:  invokeinterface #10,  1; //InterfaceMethod I1.i1Meth2:()V
       20:  return
    ...

  • How does the servlet implement the multi-thread feature?

    There is only one instance of every servlet in one wep application.
    When several clients invoke the doPost() method of the same servlet,the servlet can process their request respectively.
    So there much multi threads of one servelt.
    But the Servlet doesn't implement the Runnable interface of extends the Thread class.
    I wan't to know,how does the servlet/servlet container implement the multi-thread feature?

    Hi johnnylzb
    There is only one servlet instance existing.
    (assuming u have <load-on-startup>1</load-on-startup>)
    The server creates a thread for every request ..
    and all the threads access the same servlet instance.
    For this its not necessary for the Servlet to extend Thread or Runnable.
    hope this helps

  • How do i tell the arraylist that i want to get customer object at index i

    hi,
    i am using arraylist to add customers... i am trying to get customer info at at the specified index but i keep getting the error message " found object... required Customer"
    There is a way to tell the arraylist that the object is Customer . i know this Cause my teacher told us this last week.. but i forgot... so please can u guys plz tell me how to do it.
    thanks
    package banking.domain;
    import java.util.*;
    * The Bank class implements the Singleton design pattern, because
    * there should be only one bank object.
    public class Bank {
       * The class variable that holds the single Bank instance.
      private static final Bank bankInstance = new Bank();
      public static Bank getBank() {
        return bankInstance;
    // private static final int MAX_CUSTOMERS = 10;
      private static final double SAVINGS_RATE = 3.5;
      //private Customer[] customers;
      private Customer c;
      private ArrayList customers = new ArrayList();
    int i =0;
      private int        numberOfCustomers;
      private Bank() {
       // customers = new Customer[MAX_CUSTOMERS];
        numberOfCustomers = 0;
      public void addCustomer(String f, String l) {
         i = numberOfCustomers++;
        //customers[i] = new Customer(f, l);
        customers.add(i, new Customer(f,l));
      public Customer getCustomer() {
        //return customers[customer_index];
        return customers.get(i);
      public int getNumOfCustomers() {
        return numberOfCustomers;
    }

    hi,
    i think i fixed it.. well the error has gone so i must have.
    is this casting.. i saw sumthing similar to this on an article about casting
    Customer c = (Customer)customers.get(d);
    anyway thanks

  • How to delete the index for the business object BUS0033

    Hi to all experts,
    I'm applying note 1349496 the error here is no records with F4 help for the funds center .
    solution from the note
    Implement the attached program corrections. Then, in the transaction, delete the index for the business object BUS0033, reactivate it, and start the indexing in the indexing mode "Full". The system then displays the data correctly in the F4 search help.
    how to do the second part i have already applied the note .

    any help

  • A java List that implements the Stream interface?

    Hello,
    I just took some time to start looking into the java-8 buzz about streams and lambdas.
    And have a couple of questions...
    The first thing that surprised me is that you cannot apply the streams operations,
    like .map(), .filter() directly on a java.util.List.
    First question:
    Is there a technical reason why the java.util.List interface was not extended with
    default-implementations of these streams operations? (I guess there is...?)
    Googling a bit, I see lots of examples of people coding along the pattern of:
        List<String> list = someExpression;
        List<String> anotherList = list.stream().map(x -> f(x)).collect(Collectors.toList());
    which becomes very clumsy, if you have a lot of these stream-operations in your code.
    Since .stream() and .collect() are completely irrelevant to what you want to express,
    you would rather like to say:
        List<String> list = someExpression;
        List<String> anotherList = list.map(x -> f(x));
    What I first did as a workaround, was to implement (see code below)
    a utility interface FList, and a utility class FArrayList (extending ArrayList with .map() and .filter()).
    (The "F" prefixes stand for "functional")
    Using these utilities, you now have two options to create less clumsy code:
        List<String> list = someExpression;
        List<String> anotherList = FList.map(list, x -> f(x));
        List<String> thirdList = FList.filter(list, somePredicate);
    or better:
        FList<String> list = new FArrayList<String>(someExpression);
        FList<String> anotherList = list.map(x -> someFunction(x));
        FList<String> thirdList = list.filter(somePredicate);
    My second question:
    What I would really like to do is to have FArrayList implement the
      java.util.stream.Stream interface, to fully support the java-8 functional model.
    Since that involves implementing some 40 different methods, I would just like to know,
    if you know somebody has already done this kind of work, and the code is
    available somewhere as a public jar-file or open-source?
        public interface FList<T> extends List<T> {
            public static <A, B> List<B> map(List<A> list, Function<A, B> f) {
                return list.stream().map(f).collect(Collectors.toList());
            public static <A> List<A> filter(List<A> list, Predicate<A> f) {
                return list.stream().filter(f).collect(Collectors.toList());
            default <R> FList<R> map(Function<T, R> f) {
                FList<R> result = new FArrayList<R>();
                for (T item : this) {
                    result.add(f.apply(item));
                return result;
            default FList<T> filter(Predicate<T> p) {
                FList<T> result = new FArrayList<T>();
                for (T item : this) {
                    if (p.test(item)) {
                        result.add(item);
                return result;
        public class FArrayList<T> extends ArrayList<T> implements List<T>, FList<T> {
            private static final long serialVersionUID = 1L;
            public FArrayList() {
                super();
            public FArrayList(List<T> list) {
                super();
                this.addAll(list);

    I believe SSH and telnet are used for interactive command line sessions, don't know how you want to use them in a program.

  • Why to take refrence of ArrayList in it's interface List

    hi all
    as i am new to java n found a strange thing in various books that
    when they make object of ArrayList thye took it's refrence in List i.e its interface type ,i know by doing so we costrained the limit of arraylist object as it only use methods defined in list ,so my question is why to assign ArrayList object's refrence to List type,as we cannot take full advantage of Arraylist's class methods
    Thanks

    Suppose you only need a "thing" with the functionality of a List. You
    couldn't care less then if I gave you an ArrayList, LinkedList or whatever
    list; as long as it implements the List interface.
    kind regards,
    Jos

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

  • The XElement class explicitly implements the IXmlISerializable interface?

    I see a sentence on a training book.
    "The XElement class explicitly implements the IXmlSerializable
    interface, which contains the GetSchema, ReadXml, and
    WriteXml methods so this object can be serialized."
    I don't understand it. From
    the example, explicitly implements the IXmlSerializable interface is from a custom class rather than XElement class. Is
    MSDN wrong?

    I mean in the stackoverflow example,the class is a customized one "MyCalendar:IXmlSerializable"
    public class MyCalendar : IXmlSerializable
    private string _name;
    private bool _enabled;
    private Color _color;
    private List<MyEvent> _events = new List<MyEvent>();
    public XmlSchema GetSchema() { return null; }
    public void ReadXml(XmlReader reader)
    If XElement is a class that implements IXmlSerializable, what is the detail then?
    public class XElement : IXmlSerializable
    public XmlSchema GetSchema() { *detail*?; }
    public void ReadXml(XmlReader reader){*detail*?}
    Any source code of XElement class?

  • Implements the method defined in interface

    I defined a interface such as
    interface IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission);
    In java 5, why does compiler not accept the method checkPermission signature of the following class
    class Auth1 implements IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission){
    Iclass Auth1 implements IAuthorizer{
    boolean checkPermission(Set subj, Set Permission){
    nstead, the compiler only accepts

    <If you compile the interface and the class in the same time (eg not having the interface in a jar file against which to compile the class), the compiler should accept your code.>
    The interface and class is even in the same package. The compiler does not accept method signature as
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> perms)
    <If your interface is part of a library jar file, could it be that
    - the library is obfuscated using an obfuscater that doesn't know about generics?
    - the class is written against JDK 1.4 API (in which Set is not generic)?
    - the class is compiled using java 1.4 compiler?
    >
    no library is involved in the issue.
    class is written in JDK 1.5 API and use JDK 1.5 compiler.

  • Reg Implementing the interfaces in JDBC

    Hi,
    When we do a program that deals with database connectivity,we are not implementing the Interfaces like Statement,ResultSet.But we are using those
    interfaces inside our program.
    Can anybody justify how it is possible.
    Thanks in advance

    The DB vendors are responsible for providing implementation classes for these interfaces. That's why we need to keep DB specific jar files in CLASSPATH when we do DB activities..
    Gautam

  • Implementing the Serializable interface

    Hi guys,
    I have a conceptual question about implementing the Serializable interface - since it's only a marker interface (i.e. - it doesn't have any abstract methods) why does Java demand an object to implement this interface in order to be written into a file? What I'm asking is why wouldn't they make the writeObject method's signature
    public void writeObject(*Object* o)
    so any object can get in? What is the point of forcing a class to implement an interface in order to enable it to be written to a file?

    So that serialization requires the explicit consent of the class or superclass/superinterface.

  • I have an iTunes account where I have downloaded Digital movies & I am able to see the list on the desktop of the original downloads. When I log on another device with my login I do not see my list to access them. Why can't I access from another device

    I have an iTunes account where I have downloaded Digital movies & I am able to see the list on the desktop of the original downloads. When I log on another device with my login I do not see my list to access them. Why can't I access from another device

    Hey GingCarv,
    Great question. You'll want to download the movies from your purchase history. The following article explains how to do so:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    Note: At this time, movies are not available for automatic downloads.
    Thanks,
    Matt M.

Maybe you are looking for

  • Exchange 2013 CU5 fresh install suffering issues with services not starting and coexistence with 2007

    Hi everyone, Hope you can help me out on a couple of issues I've been experiencing during the initial stages of a project to upgrade an on premise Exchange 2007 to 2013. On Monday last week I installed the first Exchange 2013 server into the network

  • Document in xml - Not serializable? Well, I need to cache it.

    Can anyone tell me how can I serialize DOM Document. When we try to put it in cache, cache complains that it is not serializable (I believe ElementImpl is not Serializable). In javadoc it shows serializable form for this Element, but when I look in t

  • Documents downloaded via Firefox won't print or appear in preview

    Documents opened with Firefox won't print or even appear in preview. The document can be viewed but won't print. When trying to print (or see in preview) only a blank page appears. This happens even when the document is saved or made a PDF file. This

  • Sql injection character fields

    Is it true that with MSSQL in the background, character fields can't be used for sql injection? A)   One source says that in MSSQL single quotes are escaped into double quotes. B)   Another source says that " SQL injection (within ColdFusion apps) is

  • Strange problem with results ordering

    Hi! I select some varchar2 data and order them: SELECT rownum, xyz FROM analitika where xyz <= 'ABC' order by xyz This is pretty straightforward, no problems expected here, right? However, the results, when read as they pour in, are not ordered. I ge