JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label ArrayList Reference Variable. Show all posts
Showing posts with label ArrayList Reference Variable. Show all posts

Difference between a List and ArrayList Reference Variable in Java?

3:25 AM
what is the difference between  List  and  ArrayList ?    Why not just store the ArrayList object in the ArrayList variable just like we do for String, int, and other data types.? The main difference between List and ArrayList is that List is an interface while ArrayList is a class it implements the List interface, which also means that ArrayList is a subtype of List interface.In Java or any object oriented language, super type of variable can store an object of subtype. This is known as Polymorphism because any virtual method will be executed from subclass only, even though they were called from super type. Why store ArrayList object on List variable? You might have seen something like this: List<Movie> listOfMovies = new ArrayList<Movie> () here we are using a List as a type of variable to store an object of ArrayList class, created using new() operator. This is known as programming for the interfaces. In fact, everywhere you need to declare a refere

.