aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes COLLECTION PROBLEM PLEASE EXPLAIN!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "COLLECTION PROBLEM PLEASE EXPLAIN!!" Watch "COLLECTION PROBLEM PLEASE EXPLAIN!!" New topic
Author

COLLECTION PROBLEM PLEASE EXPLAIN!!

himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
hi guys, finally i completed my collections and generics from k&b i was quite sure that i no everything about this chapter and can solve all its problems.......
but there are lots of things that k&b hadnt mentioned even......things are directly coming out in questions.
for example, in this question:


public static void main(string arg[])
{
Queue<String> q=new LinkedList<String>(); //how queue<string> is refering linked list,it should give error here.SO KINDLY EXPLAIN ABOUT THIS!!
q.add("ver");
q.add("wall");
q.add("dun");
showAll(q);
}
public static void ShowAll(Queue q)
{
q.add(new Integer(42));
while(!q.isEmpty())
System.out.println(q.remove()+" ");
}
what is the result?

I AM GETTING EVERYTHING in this program but only the commented line i am not getting at al l!!
ANS: ver wall dun 42



SCJP 5
vamsi kris
Greenhorn

Joined: Feb 04, 2009
Posts: 28

its because LinkedList implements Queue interface also


SCJP 1.5 97%
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
LinkedList implements List and Queue interface both..hence this statement is valid.


My Techie Blog - Java Questions
himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
:sleephhhhh shit.......i just forgot it it just sliped from my mind.......
thank you guys 4 answering me patiently!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: COLLECTION PROBLEM PLEASE EXPLAIN!!