Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

COLLECTION PROBLEM PLEASE EXPLAIN!!

 
himanshu kesarwani
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
vamsi kris
Greenhorn
Posts: 28
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its because LinkedList implements Queue interface also
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LinkedList implements List and Queue interface both..hence this statement is valid.
 
himanshu kesarwani
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:sleephhhhh shit.......i just forgot it it just sliped from my mind.......
thank you guys 4 answering me patiently!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic