Difference between different implementations assigned to a wider type in Java

I know its best practice is to assign subclass implementations to interface type variables to provide this flexibility:

List<Integer> list = new ArrayList<Integer>();

      

My real understanding is that when you declare list

as a type, list

you limit its functionality to only the implementation of methods that type list

, and do not allow implementation-specific methods. However, what's the difference between:

List<Integer> list = new ArrayList<Integer>();

      

and

List<Integer> list = new LinkedList<Integer>();

      

Apart from some obvious performance differences caused by different implementations of each class for the List interface, are there any differences?

As another example using Set

, I know that doing:

Set<String> set = new HashSet<String>();

      

gives HashSet

how Set

, whereas:

Set<String> set = new TreeSet<String>();

      

gives TreeSet

as Set

, which means (among other things) that it is Set

automatically sorted. But not automatic sorting of an implementation-specific function of a class?

+3
java list set


source to share


No one has answered this question yet

Check out similar questions:

6170
Is Java "pass-by-reference" or "pass-by-value"?
3799
How do I read / convert an InputStream to a string in Java?
3545
Differences between HashMap and Hashtable?
3324
How to generate random integers in a specific range in Java?
3119
What is the difference between Python list methods that are appended and expanded?
2956
What is the difference between public, secure, batch and private in Java?
2936
When to use LinkedList over ArrayList in Java?
1989
"implements Runnable" vs "extends Thread" in Java
1498
Difference between StringBuilder and StringBuffer
1367
Fastest way to determine if an integer square root is an integer



All Articles
Loading...
X
Show
Funny
Dev
Pics