File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collecction/Generics 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 "Collecction/Generics" Watch "Collecction/Generics" New topic


Anu Bhagat
Ranch Hand

Joined: Jun 20, 2008
Posts: 64
Hope this is the right place to ask java certification question.

If not please let me know where I i should ask.

Any How here is my question.

I have this code which compiles fine.

Code -----------------------------

import java.util.*;

public class Test {

public static void main() {

LinkedList<String> x = new LinkedList<String>(); #1





Why does it compile? ArrayList does not have poll method. it doesn't inherit it either. I tried to read API several times. The poll method is in Queue,
so I think the line #1 can be only the line below.
Queue<String> x = new PriorityQueue<String>();

What am I missing here? Please explain.
This is my first time asking question here, so forgive me if this is not the right place to post a question.

Thanks in advance.

Anu Bhagat

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Hi Anu, In the above example where have you used ArrayList?

You have used LinkedList which implements Queue Interface, so the poll() method works.

Hope this helps.
Anu Bhagat
Ranch Hand

Joined: Jun 20, 2008
Posts: 64
Thank you very much. I see what I missed. I was typing LinkedList and thinking ArrayList, so iw wasn't working for me. Thanks for clarifying.


Anu Bhagat
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Welcome to JavaRanch.

Please use code tags when you post source code.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
wood burning stoves
subject: Collecction/Generics
It's not a secret anymore!