• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing and accessing elements from a LinkedList and ArrayList

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , i read that a LinkedlIST stores the elements in a FIFO order so its best
suited when we want to implement a Queue




When i accssed the elements uisng a Iterator the output is

sss1
sss2
sss3
sss4

and also the output is same when i used the



sss1
sss2
sss3
sss4


so please tell me whre is the diffrence?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread.
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A LinkedList implements the Queue interface as well as the List interface (ArrayList doesn't), but to get it to behave like a queue you've got to use the methods in that interface. You're just using the List interface - adding values and then iterating through them in order. All classes implementing List ought to behave the same way doing that.

Try this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic