• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection  RSS feed

 
neha. bajaj
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both these methods are declared in the List interface. Check the javadoc
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Welcome to JavaRanch
 
neha. bajaj
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:and Welcome to JavaRanch


Thank you Seetharaman.
 
neha. bajaj
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output [I@1172e08

How to get output of this code in some meaningful way ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or by using proper generics you can get rid of the cast:
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!