Mahmudul Hasan
Mahmudul Hasan

Reputation: 23

Can I create any object of ArrayList in a Queue?

I am trying to do this:

Queue<Integer> Q = new ArrayList<Integer>();

But My IDE gives me error.

Can any one please tell me, Why I can't create an object of ArrayList in a class of queue?

Upvotes: 0

Views: 2665

Answers (2)

Sujit
Sujit

Reputation: 101

Using of ArrayDeque instead of LinkedList makes it a little bit faster ...

Queue<Integer> q = new ArrayDeque<>();

Upvotes: 0

user1907906
user1907906

Reputation:

You can't do that because ArrayList does not implement Queue. You could use a LinkedList instead:

Queue<Integer> q = new LinkedList<>();

Upvotes: 4

Related Questions