aspose file tools
The moose likes Java in General and the fly likes Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Collection " Watch "Collection " New topic
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
    
  19

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)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Collection
 
Similar Threads
Exception while using arrays.aslist() method
Need help on generics
Conversion of Arrays to List - code causing compiler error
Doubt in K&B SCJP 5: topic Converting Arrays to Lists to Arrays
Understanding List and String.