• Post Reply Bookmark Topic Watch Topic
  • New Topic

why is the deque method not showing result  RSS feed

 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a program on generics - with linkedlist. Here i enque i.e. add elements in the list. Then i deque i.e. remove elements. but enque i.e. addition is working properly. But deque .i.e removal is not functioning and the result after deque is the same as after enque. what is the reason ?



main()



output -

After enque : [10, 20, 30, 40, 50]
After deque : [10, 20, 30, 40, 50]
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because your deque() method calls the List.remove(Object o) method, not List.remove(int index).  Since you don't have anything in the list that equals 0 or 2, nothing gets removed.

Your code totally misses the point of using generics: It only works with Integers.  Any other type will produce errors.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!