0

What is the difference ?

List list = new List(); LinkedList Llist;

list.add(anyString); for example and Llist.AddFirst(anyString);

4 Answers4

0

In which language? In Java (and probably also the language you use) List is just an interface for various types of Lists. You can have single linked lists, double linked lists, circular lists etc.

Markus
  • 2,526
  • 4
  • 28
  • 35
0

In Java:

List is an interface, it does not provide a concrete implementation but only the definition of which operations are possible for classes implementing this interface. I.e. each implementation of List must provide a size() method returning the number of elements in the list.

LinkedList is a concrete implementation. It supports all the methods of List (probably some more, specific to its implementation). As the name suggests, it is implementing the interface using the linked list approach.

A different List implementation would be ArrayList, which is internally using an array to implement the interface.

In C#:

In C# the naming is different. List is a concrete implementation of IList. Therefore IList is the interface, and List is the ArrayList implementation. There is also a LinkedList in C#.

D.R.
  • 20,268
  • 21
  • 102
  • 205
0

First of all, you need to understand Interface and Implementation class in Java. List is interface and LinkedList is concrete class implementing List interface.

new keyword and constructor symbol () is used to instantiate (create object) for concrete classes, but cannot be used for Interface

List list = new List();       //cannot compile as List is Interface
List list = new ArrayList();  //Valid and can compile
List list = new LinkedList(); //Valid and can compile

Before you go deep into java.util.Collection package, you should learn basic Java well.

Wundwin Born
  • 3,467
  • 19
  • 37
0

Assuming Java.in java there are many libraries that we can work from each has its own objects so List belong to java.awt library while LinkedList belongs to java.util.

about add and addFirst() I think the difference will be like this list.add(A) list.add(B) list.addFirst(C) if you printed the list you will find the order is C A B hope it helped

john-salib
  • 724
  • 1
  • 12
  • 27