| Author |
Collection
|
neha. bajaj
Ranch Hand
Joined: Jul 15, 2012
Posts: 31
|
|
Hello,
ArrayList class has size() and get() methods, so to invoke these methods on an ArrayList object is fine but how this is going on a List interface reference ?
|
 |
Aniruddh Joshi
Ranch Hand
Joined: Jul 29, 2008
Posts: 275
|
|
|
Both these methods are declared in the List interface. Check the javadoc
|
Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
neha. bajaj wrote:Hello,
ArrayList class has size() and get() methods, so to do invoke these methods on an ArrayList object is fine but how this is going on an List interface reference ?
because, ArrayList implements List and List declare get,size methods.
I assume you are also wondering how List changes are reflected in to backed array?
from asList javadoc:
Returns a fixed-size list backed by the specified array. (Changes to
* the returned list "write through" to the array.)
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
and Welcome to JavaRanch
|
 |
neha. bajaj
Ranch Hand
Joined: Jul 15, 2012
Posts: 31
|
|
Seetharaman Venkatasamy wrote:and Welcome to JavaRanch 
Thank you Seetharaman.
|
 |
neha. bajaj
Ranch Hand
Joined: Jul 15, 2012
Posts: 31
|
|
output [I@1172e08
How to get output of this code in some meaningful way ?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Or by using proper generics you can get rid of the cast:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16817
|
|
Seetharaman Venkatasamy wrote:
Rob Spoor wrote:Or by using proper generics you can get rid of the cast:
I think that this may be a case of answering the question, but ignoring the problem -- as it seems that the OP is under the impression that the asList() method will convert an array of primitives into a list of wrapped objects.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: Collection
|
|
|